cgroup: always read the supported controllers from the root cgroup of the local container
authorLennart Poettering <lennart@poettering.net>
Thu, 3 Sep 2015 17:50:37 +0000 (19:50 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 4 Sep 2015 07:07:31 +0000 (09:07 +0200)
Otherwise we might end up thinking that we support more controllers than
actually enabled for the container we are running in.

src/basic/cgroup-util.c
src/test/test-cgroup-util.c

index fe8750d..388bd62 100644 (file)
@@ -1981,14 +1981,22 @@ int cg_mask_supported(CGroupMask *ret) {
         if (unified < 0)
                 return unified;
         if (unified > 0) {
-                _cleanup_free_ char *controllers = NULL;
+                _cleanup_free_ char *root = NULL, *controllers = NULL, *path = NULL;
                 const char *c;
 
                 /* In the unified hierarchy we can read the supported
                  * and accessible controllers from a the top-level
                  * cgroup attribute */
 
-                r = read_one_line_file("/sys/fs/cgroup/cgroup.controllers", &controllers);
+                r = cg_get_root_path(&root);
+                if (r < 0)
+                        return r;
+
+                r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path);
+                if (r < 0)
+                        return r;
+
+                r = read_one_line_file(path, &controllers);
                 if (r < 0)
                         return r;
 
index ecc9d70..ff7e459 100644 (file)
@@ -295,6 +295,17 @@ static void test_shift_path(void) {
         test_shift_path_one("/foobar/waldo", "/fuckfuck", "/foobar/waldo");
 }
 
+static void test_mask_supported(void) {
+
+        CGroupMask m;
+        CGroupController c;
+
+        assert_se(cg_mask_supported(&m) >= 0);
+
+        for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++)
+                printf("'%s' is supported: %s\n", cgroup_controller_to_string(c), yes_no(m & CGROUP_CONTROLLER_TO_MASK(c)));
+}
+
 int main(void) {
         test_path_decode_unit();
         test_path_get_unit();
@@ -309,6 +320,7 @@ int main(void) {
         test_controller_is_valid();
         test_slice_to_path();
         test_shift_path();
+        test_mask_supported();
 
         return 0;
 }