Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 540160 | Differences between
and this patch

Collapse All | Expand All

(-)a/dev-libs/libcgroup/files/cgconfig.confd (-1 / +4 lines)
Lines 1-4 Link Here
1
# /etc/conf.d/cgconfig: config file for /etc/init.d/cgconfig
1
# /etc/conf.d/cgconfig: config file for /etc/init.d/cgconfig
2
2
3
# Configuration file location
3
# Configuration file location
4
#CONFIG_FILE=/etc/cgroup/cgconfig.conf
4
CG_CONFIGFILE=/etc/cgroup/cgconfig.conf
5
6
# Enable calssifying pid according to rules if necessary
7
CG_CLASSIFY=No
(-)a/dev-libs/libcgroup/files/cgconfig.initd (-107 / +43 lines)
Lines 1-117 Link Here
1
#!/sbin/runscript
1
#!/sbin/runscript
2
#
2
# Copyright 1999-2015 Gentoo Foundation
3
# Control Groups Configuration Startup
3
# Distributed under the terms of the GNU General Public License v2
4
#
4
# $Header: /etc/init.d/cgconfig,v 1.1 2015/02/18 09:53:59 tokiclover Exp $
5
# This script runs the cgconfigparser utility to parse and setup
6
# the control group filesystem. It uses ${CONFIG_FILE}
7
# and parses the configuration specified in there.
8
#
9
CGCONFIGPARSER="/usr/sbin/cgconfigparser"
10
CGROUP_FS="cgroup"
11
CONFIG_FILE=${CONFIG_FILE:-"/etc/cgroup/cgconfig.conf"}
12
MOUNTS_FILE="/proc/mounts"
13
RULES_FILE="/etc/cgroup/cgrules.conf"
14
15
# Support multiple mount points
16
MAX_INDEX=0
17
declare -a MOUNT_POINTS MOUNT_OPTIONS
18
19
move_all_to_init_class() {
20
	local i
21
	for i in $(seq 1 ${MAX_INDEX}); do
22
		cd ${MOUNT_POINTS[$i]}
23
24
		if grep -qw ${MOUNT_POINTS[$i]} ${MOUNTS_FILE}; then
25
			local directory
26
			for directory in $(find . -depth -type d); do
27
				if [[ ${directory} != "." ]]; then
28
					# cat fails with "Argument list too long" error
29
					sed -nu p < ${directory}/tasks > tasks
30
					rmdir ${directory}
31
				fi
32
			done
33
		else
34
			ewarn "Resource control filesystem not mounted"
35
		fi
36
5
37
		cd - >/dev/null
6
CGCONFIGPARSER="/usr/sbin/cgconfigparser"
38
	done
7
CGCLASSIFY="/usr/sbin/cgclassify"
39
}
8
:	${CG_CONFIGFILE:=/etc/cgroup/cgconfig.conf}
40
9
description="Control Group Configuration Service"
41
parse_mounts() {
10
42
	local device mount_point fs_type options other
11
start()
43
	while read device mount_point fs_type options other; do
12
{
44
		if grep -q ${device} <<< ${CGROUP_FS}; then
13
	ebegin "Setting up CGroups"
45
			let MAX_INDEX++
14
	${CGCONFIGPARSER} --load=${CG_CONFIGFILE} >/dev/null 2>&1
46
			MOUNT_POINTS[${MAX_INDEX}]=${mount_point}
15
	eend "$?"
47
			MOUNT_OPTIONS[${MAX_INDEX}]=${options}
48
		fi
49
	done < ${MOUNTS_FILE}
50
}
16
}
51
17
52
umount_fs() {
18
start_post()
53
	local i
19
{
54
	for i in $(seq 1 ${MAX_INDEX}); do
20
	# Classify PID according to the rules if requested
55
		umount ${MOUNT_POINTS[$i]}
21
	yesno "${CG_CLASSIFY}" || return 0
56
		rmdir ${MOUNT_POINTS[$i]}
22
	ebegin "Classifying PID to CGroups"
23
	local pid
24
	for pid in $(ps --no-headers -eL o tid); do
25
		 ${CGCLASSIFY} ${pid}
57
	done
26
	done
27
	eend "$?"
58
}
28
}
59
29
60
start() {
30
stop()
61
	ebegin "Starting cgconfig service"
31
{
62
32
	cgconfig_umount
63
	# Mount filesystem and create cgroups
64
	if ! ${CGCONFIGPARSER} -l ${CONFIG_FILE} >/dev/null; then
65
		eend 1 "Failed to parse ${CONFIG_FILE}"
66
		return 1
67
	fi
68
69
	parse_mounts
70
71
	# Find default cgroup name in rules file
72
	local default_cgroup
73
	if [[ -f ${RULES_FILE} ]]; then
74
		local user controller
75
		read user controller default_cgroup <<< $(grep -m1 '^\*\s' ${RULES_FILE})
76
		if [[ $default_cgroup == "*" ]]; then
77
			ewarn "${RULES_FILE} incorrect"
78
			ewarn "Overriding it"
79
			default_cgroup=
80
		fi
81
	fi
82
	# Use predefined name if none was found
83
	if [[ -z ${default_cgroup} ]]; then
84
		default_cgroup=sysdefault
85
	fi
86
87
	# Create a default cgroup for tasks to return back to
88
	local i
89
	for i in $(seq 1 ${MAX_INDEX}); do
90
		# Ignore if directory already exists
91
		mkdir -p ${MOUNT_POINTS[$i]}/${default_cgroup}
92
		find ${MOUNT_POINTS[$i]}/ -name tasks | xargs  chmod a+rw
93
		chmod go-w ${MOUNT_POINTS[$i]}/tasks
94
95
		# Special rule for cpusets
96
		if grep -qw cpuset <<< ${MOUNT_OPTIONS[$i]}; then
97
			cat ${MOUNT_POINTS[$i]}/cpuset.cpus > ${MOUNT_POINTS[$i]}/${default_cgroup}/cpuset.cpus
98
			cat ${MOUNT_POINTS[$i]}/cpuset.mems > ${MOUNT_POINTS[$i]}/${default_cgroup}/cpuset.mems
99
		fi
100
101
		# Classify everything to default cgroup
102
		local j
103
		for j in $(ps --no-headers -eL o tid); do
104
			echo $j > ${MOUNT_POINTS[$i]}/${default_cgroup}/tasks 2>/dev/null
105
		done
106
	done
107
108
	eend 0
109
}
33
}
110
34
111
stop() {
35
cgconfig_umount()
112
	ebegin "Stopping cgconfig service"
36
{
113
	parse_mounts
37
	local ctrl eq mnt_pnt mnt_pts
114
	move_all_to_init_class
38
115
	umount_fs
39
	while read ctrl eq mnt_pnt; do
116
	eend 0
40
		case "${ctrl}" in
41
			(\#*)    continue    ;;
42
			(mount*) mnt_pts=true;;
43
			(\}*)    mnt_pts=    ;;
44
			(*)
45
				[ -n "${mnt_pts}" ] || continue
46
				mnt_pnt="${mnt_pnt%;}"
47
				ebegin "Unmounting ${mnt_pnt}"
48
				umount "${mnt_pnt}"
49
				eend "$?"
50
				;;
51
		esac
52
	done < "${CG_CONFIGFILE}"
117
}
53
}

Return to bug 540160