diff options
author | Steve Arnold <nerdboy@gentoo.org> | 2011-03-05 17:35:52 +0000 |
---|---|---|
committer | Steve Arnold <nerdboy@gentoo.org> | 2011-03-05 17:35:52 +0000 |
commit | 2921e0869191be2310b4f1f091e581784e32d2a4 (patch) | |
tree | 21e3eccefe9131b5a547caf75f18e4b875c150f3 /dev-libs/libcgroup | |
parent | Added DEPEND on slotted gtk+-2, to work with upcoming gtk-3. (diff) | |
download | gentoo-2-2921e0869191be2310b4f1f091e581784e32d2a4.tar.gz gentoo-2-2921e0869191be2310b4f1f091e581784e32d2a4.tar.bz2 gentoo-2-2921e0869191be2310b4f1f091e581784e32d2a4.zip |
New ebuild for configuring/managing kernel control groups.
(Portage version: 2.1.9.41/cvs/Linux x86_64)
Diffstat (limited to 'dev-libs/libcgroup')
-rw-r--r-- | dev-libs/libcgroup/ChangeLog | 13 | ||||
-rw-r--r-- | dev-libs/libcgroup/files/cgconfig.confd | 4 | ||||
-rw-r--r-- | dev-libs/libcgroup/files/cgconfig.initd | 121 | ||||
-rw-r--r-- | dev-libs/libcgroup/files/cgred.confd | 17 | ||||
-rw-r--r-- | dev-libs/libcgroup/files/cgred.initd | 41 | ||||
-rw-r--r-- | dev-libs/libcgroup/files/libcgroup-0.37-wildcard-substitutions.patch | 131 | ||||
-rw-r--r-- | dev-libs/libcgroup/libcgroup-0.37-r1.ebuild | 103 | ||||
-rw-r--r-- | dev-libs/libcgroup/metadata.xml | 21 |
8 files changed, 451 insertions, 0 deletions
diff --git a/dev-libs/libcgroup/ChangeLog b/dev-libs/libcgroup/ChangeLog new file mode 100644 index 000000000000..a24026ed22dc --- /dev/null +++ b/dev-libs/libcgroup/ChangeLog @@ -0,0 +1,13 @@ +# ChangeLog for dev-libs/libcgroup +# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2 +# $Header: /var/cvsroot/gentoo-x86/dev-libs/libcgroup/ChangeLog,v 1.1 2011/03/05 17:35:52 nerdboy Exp $ + +*libcgroup-0.37-r1 (05 Mar 2011) + + 05 Mar 2011; Steve Arnold <nerdboy@gentoo.org> +libcgroup-0.37-r1.ebuild, + +files/libcgroup-0.37-wildcard-substitutions.patch, +files/cgconfig.confd, + +files/cgconfig.initd, +files/cgred.confd, +files/cgred.initd, + +metadata.xml: + New ebuild for managing kernel control groups. Based on several ebuilds + from the overlay, bugzilla, and hparker. Works for me... + diff --git a/dev-libs/libcgroup/files/cgconfig.confd b/dev-libs/libcgroup/files/cgconfig.confd new file mode 100644 index 000000000000..e41730ae0ea5 --- /dev/null +++ b/dev-libs/libcgroup/files/cgconfig.confd @@ -0,0 +1,4 @@ +# /etc/conf.d/cgconfig: config file for /etc/init.d/cgconfig + +# Configuration file location +#CONFIG_FILE=/etc/cgroup/cgconfig.conf diff --git a/dev-libs/libcgroup/files/cgconfig.initd b/dev-libs/libcgroup/files/cgconfig.initd new file mode 100644 index 000000000000..72bc9fe22811 --- /dev/null +++ b/dev-libs/libcgroup/files/cgconfig.initd @@ -0,0 +1,121 @@ +#!/sbin/runscript +# +# Control Groups Configuration Startup +# +# This script runs the cgconfigparser utility to parse and setup +# the control group filesystem. It uses ${CONFIG_FILE} +# and parses the configuration specified in there. +# +CGCONFIGPARSER="/usr/sbin/cgconfigparser" +CGROUP_FS="cgroup" +CONFIG_FILE=${CONFIG_FILE:-"/etc/cgroup/cgconfig.conf"} +MOUNTS_FILE="/proc/mounts" +RULES_FILE="/etc/cgroup/cgrules.conf" + +# Support multiple mount points +MAX_INDEX=0 +declare -a MOUNT_POINTS MOUNT_OPTIONS + +move_all_to_init_class() { + local i + for i in $(seq 1 ${MAX_INDEX}); do + cd ${MOUNT_POINTS[$i]} + + if grep -qw ${MOUNT_POINTS[$i]} ${MOUNTS_FILE}; then + local directory + for directory in $(find . -depth -type d); do + if [[ ${directory} != "." ]]; then + # cat fails with "Argument list too long" error + sed -nu p < ${directory}/tasks > tasks + rmdir ${directory} + fi + done + else + ewarn "Resource control filesystem not mounted" + fi + + cd - >/dev/null + done +} + +parse_mounts() { + local device mount_point fs_type options other + while read device mount_point fs_type options other; do + if grep -q ${device} <<< ${CGROUP_FS}; then + let MAX_INDEX++ + MOUNT_POINTS[${MAX_INDEX}]=${mount_point} + MOUNT_OPTIONS[${MAX_INDEX}]=${options} + fi + done < ${MOUNTS_FILE} +} + +umount_fs() { + local i + for i in $(seq 1 ${MAX_INDEX}); do + umount ${MOUNT_POINTS[$i]} + rmdir ${MOUNT_POINTS[$i]} + done +} + +depend() { + need local +} + +start() { + ebegin "Starting cgconfig service" + + # Mount filesystem and create cgroups + if ! ${CGCONFIGPARSER} -l ${CONFIG_FILE} >/dev/null; then + eend 1 "Failed to parse ${CONFIG_FILE}" + return 1 + fi + + parse_mounts + + # Find default cgroup name in rules file + local default_cgroup + if [[ -f ${RULES_FILE} ]]; then + local user controller + read user controller default_cgroup <<< $(grep -m1 ^\* ${RULES_FILE}) + if [[ $default_cgroup == "*" ]]; then + ewarn "${RULES_FILE} incorrect" + ewarn "Overriding it" + default_cgroup= + fi + fi + # Use predefined name if none was found + if [[ -z ${default_cgroup} ]]; then + default_cgroup=sysdefault + fi + + # Create a default cgroup for tasks to return back to + local i + for i in $(seq 1 ${MAX_INDEX}); do + # Ignore if directory already exists + mkdir -p ${MOUNT_POINTS[$i]}/${default_cgroup} + find ${MOUNT_POINTS[$i]}/ -name tasks | xargs chmod a+rw + chmod go-w ${MOUNT_POINTS[$i]}/tasks + + # Special rule for cpusets + if grep -qw cpuset <<< ${MOUNT_OPTIONS[$i]}; then + cat ${MOUNT_POINTS[$i]}/cpuset.cpus > ${MOUNT_POINTS[$i]}/${default_cgroup}/cpuset.cpus + cat ${MOUNT_POINTS[$i]}/cpuset.mems > ${MOUNT_POINTS[$i]}/${default_cgroup}/cpuset.mems + fi + + # Classify everything to default cgroup + local j + for j in $(ps --no-headers -eL o tid); do + echo $j > ${MOUNT_POINTS[$i]}/${default_cgroup}/tasks 2>/dev/null + done + done + + eend 0 +} + +stop() { + ebegin "Stopping cgconfig service" + parse_mounts + move_all_to_init_class + umount_fs + eend 0 +} diff --git a/dev-libs/libcgroup/files/cgred.confd b/dev-libs/libcgroup/files/cgred.confd new file mode 100644 index 000000000000..663ffc0c7dbd --- /dev/null +++ b/dev-libs/libcgroup/files/cgred.confd @@ -0,0 +1,17 @@ +# /etc/conf.d/cgred.conf: config file for /etc/init.d/cgred + +# Uncomment the following line to log to specified file instead of syslog +#LOG_FILE="/var/log/cgrulesengd.log" + +# Uncomment the second line to run CGroup Rules Engine in non-daemon mode +#NODAEMON="" +NODAEMON="--nodaemon" + +# Uncomment the second line to disable logging for CGroup Rules Engine +# Uncomment the third line to enable more verbose logging. +#LOG="" +LOG="--nolog" +#LOG="-v" + +# PID file +PID_FILE=/var/run/cgred.pid diff --git a/dev-libs/libcgroup/files/cgred.initd b/dev-libs/libcgroup/files/cgred.initd new file mode 100644 index 000000000000..d62039114c64 --- /dev/null +++ b/dev-libs/libcgroup/files/cgred.initd @@ -0,0 +1,41 @@ +#!/sbin/runscript +# +# CGroups Rules Engine Daemon +# +# This is a daemon for automatically classifying processes into cgroups based +# on UID/GID. +# +opts="${opts} reload" + +CGRULESENGD="/usr/sbin/cgrulesengd" +PID_FILE=${PID_FILE:-"/var/run/cgred.pid"} + +depend() { + need cgconfig local + use logger +} + +start() { + local options="${NODAEMON} ${LOG}" + if [[ -n "${LOG_FILE}" ]]; then + options="${options} --log-file=${LOG_FILE}" + fi + + ebegin "Starting CGroup Rules Engine Daemon" + start-stop-daemon --start --pidfile "${PID_FILE}" --make-pidfile \ + --background --exec "${CGRULESENGD}" -- ${options} >/dev/null + eend $? +} + +stop() { + ebegin "Stopping CGroup Rules Engine Daemon" + start-stop-daemon --stop --pidfile "${PID_FILE}" --exec "${CGRULESENGD}" + eend $? +} + +reload() { + ebegin "Reloading CGroup Rules Engine Daemon" + start-stop-daemon --stop --signal USR2 --oknodo --background \ + --pidfile "${PID_FILE}" --make-pidfile --exec "${CGRULESENGD}" + eend $? +} diff --git a/dev-libs/libcgroup/files/libcgroup-0.37-wildcard-substitutions.patch b/dev-libs/libcgroup/files/libcgroup-0.37-wildcard-substitutions.patch new file mode 100644 index 000000000000..1bcd20a01929 --- /dev/null +++ b/dev-libs/libcgroup/files/libcgroup-0.37-wildcard-substitutions.patch @@ -0,0 +1,131 @@ +From d3a300383c1973efb37dd4baf3668f0a6a75c9b2 Mon Sep 17 00:00:00 2001 +From: Michal Hrusecky <Michal@Hrusecky.net> +Date: Mon, 13 Dec 2010 16:22:37 +0100 +Subject: [PATCH] Wildcards substitutions in destinations of rules + +Rules can be written using wildcards, but destinations had to be static. +This patch adds support for following strings in destination: + + %u - uid + %U - username, uid in case of error + %g - gid + %G - group name, gid in case of error + %p - pid + %P - proccess name, pid in case of error + +So more general rules can be specified using wildcards. Example rule can +be: + +*@users * %G/%U + +This will put all users in their own cgroups named by their login and +group. + +Signed-off-by: Michal Hrusecky <Michal@Hrusecky.net> +--- + src/api.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 files changed, 81 insertions(+), 1 deletions(-) + +diff --git a/src/api.c b/src/api.c +index 859190a..29b8627 100644 +--- a/src/api.c ++++ b/src/api.c +@@ -2366,6 +2366,12 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid, + /* Temporary pointer to a rule */ + struct cgroup_rule *tmp = NULL; + ++ /* Temporary variables for destination substitution */ ++ char newdest[FILENAME_MAX]; ++ int i, j; ++ struct passwd * user_info; ++ struct group * group_info; ++ + /* Return codes */ + int ret = 0; + +@@ -2418,7 +2424,81 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid, + do { + cgroup_dbg("Executing rule %s for PID %d... ", tmp->username, + pid); +- ret = cgroup_change_cgroup_path(tmp->destination, ++ // Destination substitutions ++ for(j = i = 0; i < strlen(tmp->destination); i++, j++) { ++ if(tmp->destination[i] == '%') { ++ switch(tmp->destination[++i]) { ++ case 'u': ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%d", uid); ++ i++; ++ break; ++ case 'U': ++ user_info = getpwuid(uid); ++ if(user_info) { ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%s", ++ user_info -> ++ pw_name); ++ } else { ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%d", uid); ++ } ++ i++; ++ break; ++ case 'g': ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%d", gid); ++ i++; ++ break; ++ case 'G': ++ group_info = getgrgid(gid); ++ if(group_info) { ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%s", ++ group_info -> ++ gr_name); ++ } else { ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%d", gid); ++ } ++ i++; ++ break; ++ case 'p': ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%d", pid); ++ i++; ++ break; ++ case 'P': ++ if(procname) { ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%s", ++ procname); ++ } else { ++ j += snprintf(newdest+j, ++ FILENAME_MAX-j, ++ "%d", pid); ++ } ++ i++; ++ break; ++ default: ++ newdest[j++] = '%'; ++ } ++ } ++ if(tmp->destination[i] == '\\') ++ i++; ++ newdest[j] = tmp->destination[i]; ++ } ++ newdest[j] = 0; ++ ret = cgroup_change_cgroup_path(newdest, + pid, (const char * const *)tmp->controllers); + if (ret) { + cgroup_dbg("FAILED! (Error Code: %d)\n", ret); +-- +1.7.3.3 + diff --git a/dev-libs/libcgroup/libcgroup-0.37-r1.ebuild b/dev-libs/libcgroup/libcgroup-0.37-r1.ebuild new file mode 100644 index 000000000000..fdf392f92b41 --- /dev/null +++ b/dev-libs/libcgroup/libcgroup-0.37-r1.ebuild @@ -0,0 +1,103 @@ +# Copyright 1999-2011 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/dev-libs/libcgroup/libcgroup-0.37-r1.ebuild,v 1.1 2011/03/05 17:35:52 nerdboy Exp $ + +EAPI="2" + +inherit autotools linux-info pam + +DESCRIPTION="Tools and libraries to configure and manage kernel control groups" +HOMEPAGE="http://libcg.sourceforge.net/" +SRC_URI="mirror://sourceforge/libcg/${P}.tar.bz2" + +LICENSE="LGPL-2.1" +SLOT="0" +KEYWORDS="~amd64 ~ppc ~x86" +IUSE="+daemon debug pam static-libs +tools" + +RDEPEND="pam? ( virtual/pam )" + +DEPEND="${RDEPEND} + sys-devel/bison + sys-devel/flex" + +pkg_setup() { + if use daemon && ! use tools; then + eerror "The daemon USE flag requires tools USE flag." + die "Please enable tools or disable daemon." + fi + + local CONFIG_CHECK="~CGROUPS" + if use daemon; then + CONFIG_CHECK="${CONFIG_CHECK} ~CONNECTOR ~PROC_EVENTS" + fi + linux-info_pkg_setup +} + +src_prepare() { + # add support for wildcard rule destinations (eg, %U) + epatch "${FILESDIR}"/${P}-wildcard-substitutions.patch + + # Change rules file location + sed -e 's:/etc/cgrules.conf:/etc/cgroup/cgrules.conf:' \ + -i src/libcgroup-internal.h || die "sed failed" + sed -e 's:\(pam_cgroup_la_LDFLAGS.*\):\1\ -avoid-version:' \ + -i src/pam/Makefile.am || die "sed failed" + + eautoreconf +} + +src_configure() { + my_conf="--enable-shared + --libdir=/usr/$(get_libdir) + $(use_enable daemon) + $(use_enable debug) + $(use_enable pam) + $(use_enable static) + $(use_enable tools)" + + if use pam; then + my_conf="${my_conf} --enable-pam-module-dir=$(getpam_mod_dir)" + fi + + econf ${my_conf} +} + +src_install() { + emake DESTDIR="${D}" install || die "Install failed" + find "${D}" -name "*.la" -delete || die "la removal failed" + + insinto /etc/cgroup + doins samples/cgrules.conf || die + + if use tools; then + doins samples/cgconfig.conf || die + + newconfd "${FILESDIR}"/cgconfig.confd cgconfig || die + newinitd "${FILESDIR}"/cgconfig.initd cgconfig || die + fi + + if use daemon; then + newconfd "${FILESDIR}"/cgred.confd cgred || die + newinitd "${FILESDIR}"/cgred.initd cgred || die + fi + + head -n 24 "${FILESDIR}"/libcgroup-0.37-wildcard-substitutions.patch \ + > README.wildcards + dodoc README README.wildcards +} + +pkg_postinst() { + elog "Read the kernel docs on cgroups, related schedulers, and the" + elog "block I/O controllers. The Redhat Resource Management Guide" + elog "is also helpful. DO NOT enable the cgroup namespace subsytem" + elog "if you want a custom config, rule processing, etc. This option" + elog "should only be enabled for a VM environment. The UID wildcard" + elog "rules seem to work only without a custom config (since wildcards" + elog "don't work in config blocks). Specific user-id configs *do*" + elog "work, but be careful about how the mem limits add up if using" + elog "the memory.limit_* directives. There should be a basic task" + elog "partitioning into the default group when running cgred with no" + elog "specific config blocks or rules (other than the mount directive)." + elog "See the docs for the pam module config, and as always, RTFM..." +} diff --git a/dev-libs/libcgroup/metadata.xml b/dev-libs/libcgroup/metadata.xml new file mode 100644 index 000000000000..719ae502ac35 --- /dev/null +++ b/dev-libs/libcgroup/metadata.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> + <herd>dev-tools</herd> + <maintainer> + <email>nerdboy@gentoo.org</email> + <description>Primary maintainer</description> + </maintainer> + <longdescription> + This package provides configuration and command-line tools, as well as a rules + processing daemon for working with kernel control groups. + </longdescription> +<use> + <flag name="daemon"> + Install the configuration tools and init/config files. + </flag> + <flag name="tools"> + Install the cgroup rules processing daemon and init/config files. + </flag> +</use> +</pkgmetadata> |