]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
execute: bind init.lxc.static into container
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 3 Jun 2014 03:03:34 +0000 (22:03 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 3 Jun 2014 14:10:55 +0000 (10:10 -0400)
Changelog:

May 19: put init.lxc.static into container's root dir
rather than under SBINDIR [stgraber].

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/conf.c

index 2b298a4a6a5d3872bffeebee143dc678ea855cce..8beded29c64067d7fb5d479161099a8bf34059d2 100644 (file)
@@ -3811,6 +3811,43 @@ static void remount_all_slave(void)
                free(line);
 }
 
+void lxc_execute_bind_init(struct lxc_conf *conf)
+{
+       int ret;
+       char path[PATH_MAX], destpath[PATH_MAX];
+
+       ret = snprintf(path, PATH_MAX, SBINDIR "/init.lxc.static");
+       if (ret < 0 || ret >= PATH_MAX) {
+               WARN("Path name too long searching for lxc.init.static");
+               return;
+       }
+
+       if (!file_exists(path)) {
+               INFO("%s does not exist on host", path);
+               return;
+       }
+
+       ret = snprintf(destpath, PATH_MAX, "%s%s", conf->rootfs.mount, "/init.lxc.static");
+       if (ret < 0 || ret >= PATH_MAX) {
+               WARN("Path name too long for container's lxc.init.static");
+               return;
+       }
+
+       if (!file_exists(destpath)) {
+               FILE * pathfile = fopen(destpath, "wb");
+               if (!pathfile) {
+                       SYSERROR("Failed to create mount target '%s'", destpath);
+                       return;
+               }
+               fclose(pathfile);
+       }
+
+       ret = mount(path, destpath, "none", MS_BIND, NULL);
+       if (ret < 0)
+               SYSERROR("Failed to bind lxc.init.static into container");
+       INFO("lxc.init.static bound into container at %s", path);
+}
+
 /*
  * This does the work of remounting / if it is shared, calling the
  * container pre-mount hooks, and mounting the rootfs.
@@ -3905,6 +3942,9 @@ int lxc_setup(struct lxc_handler *handler)
                return -1;
        }
 
+       if (lxc_conf->is_execute)
+               lxc_execute_bind_init(lxc_conf);
+
        /* now mount only cgroup, if wanted;
         * before, /sys could not have been mounted
         * (is either mounted automatically or via fstab entries)