Commit 0b9c21ab by Serge E. Hallyn Committed by Daniel Lezcano

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 <serge.hallyn@canonical.com> Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/819319 Forwarded: no Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 0a1259d9
......@@ -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;
......
......@@ -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
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment