]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: try to handle layouts with no cgroups 2777/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Jan 2019 22:56:50 +0000 (23:56 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Jan 2019 22:56:50 +0000 (23:56 +0100)
Cc: Ondrej Kubik <ondrej.kubik@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index 3ab54d2d870190ed8bc6b119c129a009f50363e4..c4fc652523f2d0c46f588c2c6da7eb8d387ffbef 100644 (file)
@@ -1108,6 +1108,9 @@ __cgfsng_ops static void cgfsng_payload_destroy(struct cgroup_ops *ops,
        int ret;
        struct generic_userns_exec_data wrap;
 
+       if (!ops->hierarchies)
+               return;
+
        wrap.origuid = 0;
        wrap.container_cgroup = ops->container_cgroup;
        wrap.hierarchies = ops->hierarchies;
@@ -1376,6 +1379,9 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
        if (!conf)
                return bret;
 
+       if (!ops->hierarchies)
+               return true;
+
        if (conf->cgroup_meta.dir)
                tmp = lxc_string_join("/",
                                      (const char *[]){conf->cgroup_meta.dir,
@@ -1442,6 +1448,9 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
        if (!conf)
                return false;
 
+       if (!ops->hierarchies)
+               return true;
+
        if (conf->cgroup_meta.dir)
                tmp = lxc_string_join("/", (const char *[]){conf->cgroup_meta.dir, handler->name, NULL}, false);
        else
@@ -1505,6 +1514,9 @@ __cgfsng_ops static bool __do_cgroup_enter(struct cgroup_ops *ops, pid_t pid,
        int len;
        char pidstr[INTTYPE_TO_STRLEN(pid_t)];
 
+       if (!ops->hierarchies)
+               return true;
+
        len = snprintf(pidstr, sizeof(pidstr), "%d", pid);
        if (len < 0 || (size_t)len >= sizeof(pidstr))
                return false;
@@ -1648,6 +1660,9 @@ __cgfsng_ops static bool cgfsng_chown(struct cgroup_ops *ops,
        if (lxc_list_empty(&conf->id_map))
                return true;
 
+       if (!ops->hierarchies)
+               return true;
+
        wrap.origuid = geteuid();
        wrap.path = NULL;
        wrap.hierarchies = ops->hierarchies;
@@ -1798,6 +1813,9 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
        char *tmpfspath = NULL;
        bool has_cgns = false, retval = false, wants_force_mount = false;
 
+       if (!ops->hierarchies)
+               return true;
+
        if ((type & LXC_AUTO_CGROUP_MASK) == 0)
                return true;
 
@@ -1961,7 +1979,7 @@ __cgfsng_ops static bool cgfsng_escape(const struct cgroup_ops *ops,
 {
        int i;
 
-       if (conf->cgroup_meta.relative || geteuid())
+       if (conf->cgroup_meta.relative || geteuid() || !ops->hierarchies)
                return true;
 
        for (i = 0; ops->hierarchies[i]; i++) {
@@ -1985,9 +2003,12 @@ __cgfsng_ops static bool cgfsng_escape(const struct cgroup_ops *ops,
 
 __cgfsng_ops static int cgfsng_num_hierarchies(struct cgroup_ops *ops)
 {
-       int i;
+       int i = 0;
+
+       if (!ops->hierarchies)
+               return 0;
 
-       for (i = 0; ops->hierarchies[i]; i++)
+       for (; ops->hierarchies[i]; i++)
                ;
 
        return i;
@@ -1997,6 +2018,9 @@ __cgfsng_ops static bool cgfsng_get_hierarchies(struct cgroup_ops *ops, int n, c
 {
        int i;
 
+       if (!ops->hierarchies)
+               return false;
+
        /* sanity check n */
        for (i = 0; i < n; i++)
                if (!ops->hierarchies[i])
@@ -2138,6 +2162,9 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops, const char *name,
        int i, len, ret;
        char pidstr[INTTYPE_TO_STRLEN(pid_t)];
 
+       if (!ops->hierarchies)
+               return true;
+
        len = snprintf(pidstr, sizeof(pidstr), "%d", pid);
        if (len < 0 || (size_t)len >= sizeof(pidstr))
                return false;
@@ -2387,6 +2414,9 @@ static bool __cg_legacy_setup_limits(struct cgroup_ops *ops,
        if (lxc_list_empty(cgroup_settings))
                return true;
 
+       if (!ops->hierarchies)
+               return false;
+
        sorted_cgroup_settings = sort_cgroup_settings(cgroup_settings);
        if (!sorted_cgroup_settings)
                return false;