]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups/cgfsng: rework cgfsng_escape()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 7 Dec 2019 23:16:59 +0000 (00:16 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 7 Dec 2019 23:16:59 +0000 (00:16 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index 1638f5d528287dbda804a99190047f10fc926146..932425e813cdf61e3dc949108653999b17311095 100644 (file)
@@ -1930,23 +1930,33 @@ __cgfsng_ops static int cgfsng_nrtasks(struct cgroup_ops *ops)
 
 /* Only root needs to escape to the cgroup of its init. */
 __cgfsng_ops static bool cgfsng_escape(const struct cgroup_ops *ops,
-                                        struct lxc_conf *conf)
+                                      struct lxc_conf *conf)
 {
-       if (conf->cgroup_meta.relative || geteuid() || !ops->hierarchies)
+       if (!ops)
+               return ret_set_errno(false, ENOENT);
+
+       if (!ops->hierarchies)
+               return true;
+
+       if (!conf)
+               return ret_set_errno(false, EINVAL);
+
+       if (conf->cgroup_meta.relative || geteuid())
                return true;
 
        for (int i = 0; ops->hierarchies[i]; i++) {
-               int ret;
                __do_free char *fullpath = NULL;
+               int ret;
 
-               fullpath = must_make_path(ops->hierarchies[i]->mountpoint,
-                                         ops->hierarchies[i]->container_base_path,
-                                         "cgroup.procs", NULL);
+               fullpath =
+                   must_make_path(ops->hierarchies[i]->mountpoint,
+                                  ops->hierarchies[i]->container_base_path,
+                                  "cgroup.procs", NULL);
                ret = lxc_write_to_file(fullpath, "0", 2, false, 0666);
-               if (ret != 0) {
-                       SYSERROR("Failed to escape to cgroup \"%s\"", fullpath);
-                       return false;
-               }
+               if (ret != 0)
+                       return log_error_errno(false,
+                                              errno, "Failed to escape to cgroup \"%s\"",
+                                              fullpath);
        }
 
        return true;