]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
container start: unshare cgns when possible
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 9 Nov 2015 23:55:54 +0000 (17:55 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 8 Jan 2016 21:03:37 +0000 (13:03 -0800)
We'll probably want to make this configurable with a
lxc.cgroupns = [1|0], but for now just always do it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
---
Changelog 20160104: only try to unshare if /proc/self/ns/cgroup exists.

src/lxc/namespace.h
src/lxc/start.c
src/lxc/utils.c
src/lxc/utils.h

index 28f17e687622a0990bb9774f694f85fe5374d55a..027c765889f29d771820d4a2de70372523a02d42 100644 (file)
@@ -34,6 +34,9 @@
 #ifndef CLONE_NEWNS
 #  define CLONE_NEWNS             0x00020000
 #endif
+#ifndef CLONE_NEWCGROUP
+#  define CLONE_NEWCGROUP         0x02000000
+#endif
 #ifndef CLONE_NEWUTS
 #  define CLONE_NEWUTS            0x04000000
 #endif
index 79dbe335df9584e4bda36682d6548bc3e5a65db8..6d4d2c2114bd7efbd95716db5d40514ebc3d110b 100644 (file)
@@ -842,6 +842,11 @@ static int do_start(void *data)
        if (handler->backgrounded && null_stdfds() < 0)
                goto out_warn_father;
 
+       if (cgns_supported() && unshare(CLONE_NEWCGROUP) != 0) {
+               SYSERROR("Failed to unshare cgroup namespace");
+               goto out_warn_father;
+       }
+
        /* after this call, we are in error because this
         * ops should not return as it execs */
        handler->ops->start(handler, handler->data);
index ad9b0a294ceb26d41b289dcfa4f9d3267fd3d856..ed8c4c42de09cf3a27948436c92df0f85a405d93 100644 (file)
@@ -1185,6 +1185,11 @@ bool file_exists(const char *f)
        return stat(f, &statbuf) == 0;
 }
 
+bool cgns_supported(void)
+{
+       return file_exists("/proc/self/ns/cgroup");
+}
+
 /* historically lxc-init has been under /usr/lib/lxc and under
  * /usr/lib/$ARCH/lxc.  It now lives as $prefix/sbin/init.lxc.
  */
index 059026f0154b1713854c84674d12954a09469506..96ec45c20f09c5a96eb28089f811c5a32c59f5a1 100644 (file)
@@ -273,6 +273,7 @@ int detect_shared_rootfs(void);
 int detect_ramfs_rootfs(void);
 char *on_path(char *cmd, const char *rootfs);
 bool file_exists(const char *f);
+bool cgns_supported(void);
 char *choose_init(const char *rootfs);
 int print_to_file(const char *file, const char *content);
 bool switch_to_ns(pid_t pid, const char *ns);