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@canonical.com>
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/819319
Forwarded: no
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
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;
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
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);
}