summaryrefslogtreecommitdiff
path: root/sliceweasel.lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sliceweasel.lib.sh')
-rwxr-xr-xsliceweasel.lib.sh23
1 files changed, 14 insertions, 9 deletions
diff --git a/sliceweasel.lib.sh b/sliceweasel.lib.sh
index bbaed78..3c54841 100755
--- a/sliceweasel.lib.sh
+++ b/sliceweasel.lib.sh
@@ -55,12 +55,12 @@ get_total_io()
55 55
56root_write() 56root_write()
57{ 57{
58 $AS_ROOT sh -c 'cat > "$1"' sh "$1" 58 $AS_ROOT sh -c 'cat > "$1"' sh "$1" || true
59} 59}
60 60
61join_group() 61join_group()
62{ 62{
63 GROUP_DIR=/sys/fs/cgroup/"$1" 63 GROUP_DIR="$1"
64 [ -d "$GROUP_DIR" ] || $AS_ROOT mkdir "$GROUP_DIR" 64 [ -d "$GROUP_DIR" ] || $AS_ROOT mkdir "$GROUP_DIR"
65 echo $$ | root_write "$GROUP_DIR"/cgroup.procs 65 echo $$ | root_write "$GROUP_DIR"/cgroup.procs
66} 66}
@@ -68,13 +68,15 @@ join_group()
68add_subtree_controller() 68add_subtree_controller()
69{ 69{
70 local group="$1" controller="$2" control_file 70 local group="$1" controller="$2" control_file
71 control_file=$(realpath -e "/sys/fs/cgroup/$group/cgroup.subtree_control") || return 71 control_file="$group/cgroup.subtree_control"
72 case "$control_file" in 72
73 /sys/fs/cgroup/cgroup.subtree_control) ;; 73 [ "$group" ] && [ "$controller" ] && [ -d "$group" ] && [ -e "$control_file" ] || return
74 *) add_subtree_controller "$group"/.. "$2" ;; 74
75 case "$group" in
76 /sys/fs/cgroup) ;;
77 *) add_subtree_controller "$(realpath "$group/..")" "$2" ;;
75 esac 78 esac
76 79
77 [ "$1" ] && [ "$2" ] && [ -e "$control_file" ] || return
78 if ! grep -qe "\\b${controller}\\b" "$control_file" 80 if ! grep -qe "\\b${controller}\\b" "$control_file"
79 then 81 then
80 echo +"$controller" | root_write "$control_file" 82 echo +"$controller" | root_write "$control_file"
@@ -83,9 +85,12 @@ add_subtree_controller()
83 85
84set_max() 86set_max()
85{ 87{
86 add_subtree_controller "$1"/.. "$2"
87 max_file=$group/$2.max 88 max_file=$group/$2.max
88 [ -e "$max_file" ] || return 89 if [ ! -e "$max_file" ]
90 then
91 add_subtree_controller "$1"/.. "$2"
92 [ -e "$max_file" ] || return
93 fi
89 printf '%s\n' "$3" | root_write "$max_file" 94 printf '%s\n' "$3" | root_write "$max_file"
90} 95}
91 96