From: Christian Brauner Date: Mon, 24 Sep 2018 20:58:45 +0000 (+0200) Subject: cgfsng: set errno to ENOENT on get_hierarchy() X-Git-Tag: lxc-3.1.0~88^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27a5132c2221d44d293c4e8313732c6460b0e290;p=thirdparty%2Flxc.git cgfsng: set errno to ENOENT on get_hierarchy() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 3df279377..5475f7eff 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -179,15 +179,19 @@ static void must_append_controller(char **klist, char **nlist, char ***clist, /* Given a handler's cgroup data, return the struct hierarchy for the controller * @c, or NULL if there is none. */ -struct hierarchy *get_hierarchy(struct cgroup_ops *ops, const char *c) +struct hierarchy *get_hierarchy(struct cgroup_ops *ops, const char *controller) { int i; - if (!ops->hierarchies) + errno = ENOENT; + + if (!ops->hierarchies) { + TRACE("There are no useable cgroup controllers"); return NULL; + } for (i = 0; ops->hierarchies[i]; i++) { - if (!c) { + if (!controller) { /* This is the empty unified hierarchy. */ if (ops->hierarchies[i]->controllers && !ops->hierarchies[i]->controllers[0]) @@ -196,10 +200,15 @@ struct hierarchy *get_hierarchy(struct cgroup_ops *ops, const char *c) continue; } - if (string_in_list(ops->hierarchies[i]->controllers, c)) + if (string_in_list(ops->hierarchies[i]->controllers, controller)) return ops->hierarchies[i]; } + if (controller) + WARN("There is no useable %s controller", controller); + else + WARN("There is no empty unified cgroup hierarchy"); + return NULL; } diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h index 16b880942..292fa1c92 100644 --- a/src/lxc/cgroups/cgroup.h +++ b/src/lxc/cgroups/cgroup.h @@ -104,6 +104,7 @@ struct cgroup_ops { * hierarchy wins. */ struct hierarchy **hierarchies; + /* Pointer to the unified hierarchy. Do not free! */ struct hierarchy *unified; /* diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 09379dec9..4d542eb94 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -654,7 +654,7 @@ static int lxc_cmd_stop_callback(int fd, struct lxc_cmd_req *req, * lxc_unfreeze() would do another cmd (GET_CGROUP) which would * deadlock us. */ - if (cgroup_ops->get_cgroup(cgroup_ops, "freezer") == NULL) + if (!cgroup_ops->get_cgroup(cgroup_ops, "freezer")) return 0; if (cgroup_ops->unfreeze(cgroup_ops))