From 27a5132c2221d44d293c4e8313732c6460b0e290 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 24 Sep 2018 22:58:45 +0200 Subject: [PATCH] cgfsng: set errno to ENOENT on get_hierarchy() Signed-off-by: Christian Brauner --- src/lxc/cgroups/cgfsng.c | 17 +++++++++++++---- src/lxc/cgroups/cgroup.h | 1 + src/lxc/commands.c | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) 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)) -- 2.47.2