--- cgconfig.initd.orig +++ cgconfig.initd @@ -13,18 +13,18 @@ RULES_FILE="/etc/cgroup/cgrules.conf" # Support multiple mount points -MAX_INDEX=0 -declare -a MOUNT_POINTS MOUNT_OPTIONS +MOUNT_POINTS= move_all_to_init_class() { local i - for i in $(seq 1 ${MAX_INDEX}); do - cd ${MOUNT_POINTS[$i]} + for i in $MOUNT_POINTS; do + local mount_point=${i%:*} + cd ${mount_point} - if grep -qw ${MOUNT_POINTS[$i]} ${MOUNTS_FILE}; then + if grep -qw "${mount_point}" ${MOUNTS_FILE}; then local directory for directory in $(find . -depth -type d); do - if [[ ${directory} != "." ]]; then + if [ "${directory}" != "." ]; then # cat fails with "Argument list too long" error sed -nu p < ${directory}/tasks > tasks rmdir ${directory} @@ -41,19 +41,17 @@ 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} + if echo ${CGROUP_FS} | grep -q ${device}; then + MOUNT_POINTS="${MOUNT_POINTS} ${mount_point}:${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]} + for i in ${MOUNT_POINTS}; do + umount ${i%:*} + rmdir ${i%:*} done } @@ -74,38 +72,39 @@ # 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 + if [ -f "${RULES_FILE}" ]; then + default_cgroup=$(awk '$1 == "*" {print $3; exit}' ${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 + 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 + for i in $MOUNT_POINTS; do + local mount_point=${i%:*} + local mount_options=${i#*:} # 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 + mkdir -p ${mount_point}/${default_cgroup} + find ${mount_point}/ -name tasks | xargs chmod a+rw + chmod go-w ${mount_point}/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 + if echo ${mount_options} | grep -qw cpuset; then + cat ${mount_point}/cpuset.cpus > ${mount_point}/${default_cgroup}/cpuset.cpus + cat ${mount_point}/cpuset.mems > ${mount_point}/${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 + echo $j > ${mount_point}/${default_cgroup}/tasks 2>/dev/null done done