commit:     3fafd7a76e6adf15ec72a7ba5f44583eff8fab7a
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Sat Sep 16 22:02:52 2017 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sat Sep 16 22:02:52 2017 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3fafd7a7

sysfs: fix cgroup hybrid mode

In hybrid mode, we should not try to mount cgroup2 if it is not
available in the kernel.

This fixes #164.

 init.d/sysfs.in | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/init.d/sysfs.in b/init.d/sysfs.in
index 9f39fb57..23e8821c 100644
--- a/init.d/sysfs.in
+++ b/init.d/sysfs.in
@@ -150,6 +150,16 @@ cgroup1_controllers()
        return 0
 }
 
+cgroup2_base()
+{
+       local base
+       base="$(cgroup2_find_path)"
+       mkdir -p "${base}"
+       mount -t cgroup2 none -o "${sysfs_opts},nsdelegate" "${base}" 2> 
/dev/null ||
+               mount -t cgroup2 none -o "${sysfs_opts}" "${base}"
+       return 0
+}
+
 cgroup2_controllers()
 {
        local active cgroup_path x y
@@ -169,13 +179,12 @@ cgroup2_controllers()
 
 cgroups_hybrid()
 {
-       grep -qw cgroup /proc/filesystems &&
-               grep -qw cgroup2 /proc/filesystems ||
-               return 0
+       grep -qw cgroup /proc/filesystems || return 0
        cgroup1_base
-       mkdir /sys/fs/cgroup/unified
-       mount -t cgroup2 none -o "${sysfs_opts},nsdelegate" 
/sys/fs/cgroup/unified
-       cgroup2_controllers
+       if grep -qw cgroup2 /proc/filesystems; then
+               cgroup2_base
+               cgroup2_controllers
+       fi
        cgroup1_controllers
        return 0
 }
@@ -190,8 +199,8 @@ cgroups_legacy()
 
 cgroups_unified()
 {
-       grep -qw cgroup2 /proc/filesystems || return 0
-       mount -t cgroup2 none -o "${sysfs_opts},nsdelegate" /sys/fs/cgroup
+       cgroup2_base
+       cgroup2_controllers
        return 0
 }
 

Reply via email to