From: Serge E. Hallyn Date: Tue, 9 Aug 2011 14:51:01 +0000 (+0200) Subject: Silence lxc-unshare warning when removing cgroup X-Git-Tag: lxc-0.7.5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b9c21ab8ab3e7a1eacdb087950fe9f680053486;p=thirdparty%2Flxc.git Silence lxc-unshare warning when removing cgroup If ns cgroup is mounted, then when lxc-unshare runs, the kernel automatically creates a new cgroup for the task. So lxc-unshare tries to delete it. But if ns cgroup is not mounted, that cgroup does not get created, and now lxc-unshare spits an error. Author: Serge Hallyn Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/819319 Forwarded: no Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index c4769f97b..a2b823e2b 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -82,6 +82,13 @@ static int get_cgroup_mount(const char *subsystem, char *mnt) return -1; } +int lxc_ns_is_mounted(void) +{ + static char buf[MAXPATHLEN]; + + return (get_cgroup_mount("ns", buf) == 0); +} + static int get_cgroup_flags(struct mntent *mntent) { int flags = 0; diff --git a/src/lxc/cgroup.h b/src/lxc/cgroup.h index f6df8c538..188d94807 100644 --- a/src/lxc/cgroup.h +++ b/src/lxc/cgroup.h @@ -30,4 +30,5 @@ int lxc_cgroup_create(const char *name, pid_t pid); int lxc_cgroup_destroy(const char *name); int lxc_cgroup_path_get(char **path, const char *subsystem, const char *name); int lxc_cgroup_nrtasks(const char *name); +int lxc_ns_is_mounted(void); #endif diff --git a/src/lxc/lxc_unshare.c b/src/lxc/lxc_unshare.c index eb93c89db..0baccb007 100644 --- a/src/lxc/lxc_unshare.c +++ b/src/lxc/lxc_unshare.c @@ -210,12 +210,14 @@ int main(int argc, char *argv[]) return -1; } - if (asprintf(&pid_name, "%d", pid) == -1) { - ERROR("pid_name: failed to allocate memory"); - return -1; + if (lxc_ns_is_mounted()) { + if (asprintf(&pid_name, "%d", pid) == -1) { + ERROR("pid_name: failed to allocate memory"); + return -1; + } + lxc_cgroup_destroy(pid_name); + free(pid_name); } - lxc_cgroup_destroy(pid_name); - free(pid_name); return lxc_error_set_and_log(pid, status); }