From: Serge Hallyn Date: Thu, 15 Oct 2015 18:56:17 +0000 (+0000) Subject: Ignore trailing /init.scope in init cgroups X-Git-Tag: lxc-1.0.8~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a156301a6206e305594cb8616d3078b575ed937e;p=thirdparty%2Flxc.git Ignore trailing /init.scope in init cgroups The lxc monitor does not store the container's cgroups, rather it recalculates them whenever needed. Systemd moves itself into a /init.scope cgroup for the systemd controller. It might be worth changing that (by storing all cgroup info in the lxc_handler), but for now go the hacky route and chop off any trailing /init.scope. I definately thinkg we want to switch to storing as that will be more bullet-proof, but for now we need a quick backportable fix for systemd 226 guests. Signed-off-by: Serge Hallyn Acked-by: Stéphane Graber --- diff --git a/src/lxc/cgfs.c b/src/lxc/cgfs.c index 23e889c31..1c7cb9821 100644 --- a/src/lxc/cgfs.c +++ b/src/lxc/cgfs.c @@ -1220,6 +1220,7 @@ static char *lxc_cgroup_get_hierarchy_path_data(const char *subsystem, struct cg info = find_info_for_subsystem(info, subsystem); if (!info) return NULL; + prune_init_scope(info->cgroup_path); return info->cgroup_path; } diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c index 0f79ffb8f..922f1e2c3 100644 --- a/src/lxc/cgmanager.c +++ b/src/lxc/cgmanager.c @@ -767,6 +767,7 @@ static char *try_get_abs_cgroup(const char *name, const char *lxcpath, nerr = nih_error_get(); nih_free(nerr); } + prune_init_scope(cgroup); return cgroup; } diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 63a2ad4de..c11346d49 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -173,3 +173,17 @@ void cgroup_disconnect(void) if (ops && ops->disconnect) ops->disconnect(); } + +#define INIT_SCOPE "/init.scope" +void prune_init_scope(char *cg) +{ + char *point = cg + strlen(cg) - strlen(INIT_SCOPE); + if (point < cg) + return; + if (strcmp(point, INIT_SCOPE) == 0) { + if (point == cg) + *(point+1) = '\0'; + else + *point = '\0'; + } +} diff --git a/src/lxc/cgroup.h b/src/lxc/cgroup.h index 7e033702f..fe9c805eb 100644 --- a/src/lxc/cgroup.h +++ b/src/lxc/cgroup.h @@ -67,4 +67,6 @@ extern const char *cgroup_get_cgroup(struct lxc_handler *handler, const char *su extern bool cgroup_unfreeze(struct lxc_handler *handler); extern void cgroup_disconnect(void); +extern void prune_init_scope(char *cg); + #endif