]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Silence lxc-unshare warning when removing cgroup
authorSerge E. Hallyn <serge.hallyn@canonical.com>
Tue, 9 Aug 2011 14:51:01 +0000 (16:51 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 9 Aug 2011 14:51:01 +0000 (16:51 +0200)
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>
src/lxc/cgroup.c
src/lxc/cgroup.h
src/lxc/lxc_unshare.c

index c4769f97bb00c11e6eca6822d31639a661078785..a2b823e2b0f821fea4e8e46804e0548e646089dc 100644 (file)
@@ -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;
index f6df8c5388483d46281c6fca50ac55ca9cd38ca7..188d9480718da9b3b4a1b439c6412c884e2afcd3 100644 (file)
@@ -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
index eb93c89dbda88ee6eea56b801fe77bdae37733c2..0baccb007dfa52c1b2f530199fdb176504ebdfb1 100644 (file)
@@ -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);
 }