From 6d02c5e7ca04652bf1c180a273e12fdb82cb325c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 31 Jan 2018 16:42:19 +0100 Subject: [PATCH] cgroups: cgfsng_set: handle unified hierarchy Signed-off-by: Christian Brauner --- src/lxc/cgroups/cgfsng.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index ec5fe1006..fe3e26ec1 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -2369,28 +2369,34 @@ static int cgfsng_get(const char *filename, char *value, size_t len, * Here we don't have a cgroup_data set up, so we ask the running * container through the commands API for the cgroup path */ -static int cgfsng_set(const char *filename, const char *value, const char *name, const char *lxcpath) +static int cgfsng_set(const char *filename, const char *value, const char *name, + const char *lxcpath) { - char *subsystem, *p, *path; - struct hierarchy *h; int ret = -1; + size_t controller_len; + char *controller, *p, *path; + struct hierarchy *h; - subsystem = alloca(strlen(filename) + 1); - strcpy(subsystem, filename); - if ((p = strchr(subsystem, '.')) != NULL) + controller_len = strlen(filename); + controller = alloca(controller_len + 1); + strcpy(controller, filename); + p = strchr(controller, '.'); + if (p) *p = '\0'; - path = lxc_cmd_get_cgroup_path(name, lxcpath, subsystem); - if (!path) /* not running */ + path = lxc_cmd_get_cgroup_path(name, lxcpath, controller); + /* not running */ + if (!path) return -1; - h = get_hierarchy(subsystem); + h = get_hierarchy(controller); if (h) { - char *fullpath = build_full_cgpath_from_monitorpath(h, path, filename); + char *fullpath; + + fullpath = build_full_cgpath_from_monitorpath(h, path, filename); ret = lxc_write_to_file(fullpath, value, strlen(value), false); free(fullpath); } - free(path); return ret; -- 2.47.2