[Lxc-users] Silence lxc-unshare warning when removing cgroup
Serge E. Hallyn
serge.hallyn at canonical.com
Wed Aug 3 14:57:42 UTC 2011
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 <serge.hallyn at canonical.com>
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/819319
Forwarded: no
Index: lxc/src/lxc/cgroup.c
===================================================================
--- lxc.orig/src/lxc/cgroup.c 2011-08-01 10:22:53.319598290 -0500
+++ lxc/src/lxc/cgroup.c 2011-08-01 10:55:00.349641606 -0500
@@ -82,6 +82,13 @@
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;
Index: lxc/src/lxc/cgroup.h
===================================================================
--- lxc.orig/src/lxc/cgroup.h 2011-08-01 10:22:54.149598308 -0500
+++ lxc/src/lxc/cgroup.h 2011-08-01 10:54:52.889641439 -0500
@@ -30,4 +30,5 @@
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
Index: lxc/src/lxc/lxc_unshare.c
===================================================================
--- lxc.orig/src/lxc/lxc_unshare.c 2011-08-01 10:17:52.189591521 -0500
+++ lxc/src/lxc/lxc_unshare.c 2011-08-01 11:06:54.889657669 -0500
@@ -210,12 +210,14 @@
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);
}
More information about the lxc-users
mailing list