libcgroup now provides some tools, which can be used in the init script
instead of bash code.

Signed-off-by: Jan Safranek <[email protected]>
---

 scripts/init.d/cgconfig.in |   55 ++++++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/scripts/init.d/cgconfig.in b/scripts/init.d/cgconfig.in
index 4c3c2e8..d5649eb 100644
--- a/scripts/init.d/cgconfig.in
+++ b/scripts/init.d/cgconfig.in
@@ -87,36 +87,35 @@ create_default_groups() {
         then
             defaultcgroup=sysdefault/
         fi
+
         #
-        # Create a default class for tasks to return back to
+        # Find all mounted subsystems and create comma-separated list
+        # of controllers.
         #
-        parse_mounts
-        for i in `seq 1 $maxindex`
-        do
-            #
-            # Ignore if directory already exists
-            #
-            mkdir ${MOUNTPOINT[$i]}/$defaultcgroup 2> /dev/null
-            chmod a+rw ${MOUNTPOINT[$i]}/$defaultcgroup/tasks
-            #
-            # special rule for cpusets
-            #
-            echo ${MOUNTOPTS[$i]} | grep -q -w cpuset
-            if [ $? -eq 0 ]
-            then
-                cat ${MOUNTPOINT[$i]}/cpuset.cpus > \
-                    ${MOUNTPOINT[$i]}/$defaultcgroup/cpuset.cpus
-                cat ${MOUNTPOINT[$i]}/cpuset.mems > \
-                    ${MOUNTPOINT[$i]}/$defaultcgroup/cpuset.mems
-            fi
-            #
-            # classify everything to default cgroup
-            #
-            for j in `ps --no-headers -eL o tid`
-            do
-                echo $j > ${MOUNTPOINT[$i]}/$defaultcgroup/tasks 2>/dev/null
-            done
-        done
+        controllers=`lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//`
+
+        #
+        # Create the default group, ignore errors when the default group
+        # already exists.
+        #
+        cgcreate -g $controllers:$defaultcgroup 2>/dev/null
+
+        #
+        # special rule for cpusets
+        #
+        if echo $controllers | grep -q -w cpuset; then
+                cpus=`cgget -nv -r cpuset.cpus /`
+                cgset -r cpuset.cpus=$cpus $defaultcgroup
+                mems=`cgget -nv -r cpuset.mems /`
+                cgset -r cpuset.mems=$mems $defaultcgroup
+        fi
+
+        #
+        # Classify everything to default cgroup. Ignore errors, some processes
+        # may exit after ps is run and before cgclassify moves them.
+        #
+        cgclassify -g $controllers:$defaultcgroup `ps --no-headers -eL o tid` \
+                 2>/dev/null || :
 }
 
 start() {


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to