]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Define a new lxc.init_cmd config option
authorStéphane Graber <stgraber@ubuntu.com>
Wed, 26 Nov 2014 19:33:27 +0000 (14:33 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 1 Dec 2014 18:46:11 +0000 (13:46 -0500)
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
doc/lxc-start.sgml.in
doc/lxc.container.conf.sgml.in
doc/lxc.sgml.in
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/lxc_autostart.c
src/lxc/lxc_start.c
src/lxc/lxccontainer.c

index 950cc243b81b089855a160a486ead8b1d1386f95..1770ac2ce788bc46e93e5ec681c0e41b1befadfd 100644 (file)
@@ -80,7 +80,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     </para>
     <para>
       If no command is specified, <command>lxc-start</command> will
-      use the default
+      use the command defined in lxc.init_cmd or if not set, the default
       <command>"/sbin/init"</command> command to run a system
       container.
     </para>
index 35907b502fc2029e36f764a9168651bdef3af984..6d4daac077803fdaa3d195b8d4b31fe70ea51a7f 100644 (file)
@@ -201,6 +201,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       </variablelist>
     </refsect2>
 
+    <refsect2>
+      <title>Init command</title>
+      <para>
+        Sets the command to use as the init system for the containers.
+
+        This option is ignored when using lxc-execute.
+
+        Defaults to: /sbin/init
+      </para>
+      <variablelist>
+    <varlistentry>
+      <term>
+        <option>lxc.init_cmd</option>
+      </term>
+      <listitem>
+        <para>
+          Absolute path from container rootfs to the binary to use as init.
+        </para>
+      </listitem>
+    </varlistentry>
+      </variablelist>
+    </refsect2>
+
     <refsect2>
       <title>Network</title>
       <para>
index 1bafaf27c13750ac31ed71a829bae9f29ec56fec..c522e2b5caa46934c5c272901ddc5fe779329b0b 100644 (file)
@@ -376,7 +376,8 @@ rootfs
        command into the container.
        The pid of the first process is 1. If no command is
        specified <command>lxc-start</command> will
-       run <filename>/sbin/init</filename>.
+       run the command defined in lxc.init_cmd or if not set,
+       <filename>/sbin/init</filename> .
       </para>
 
       <para>
index ac21c77130f2a6562eac06a29be319405f603c20..90df4d256dbb30dce5e83ed228803359cd713bfe 100644 (file)
@@ -4537,6 +4537,8 @@ void lxc_conf_free(struct lxc_conf *conf)
                free(conf->fstab);
        if (conf->rcfile)
                free(conf->rcfile);
+       if (conf->init_cmd)
+               free(conf->init_cmd);
        free(conf->unexpanded_config);
        lxc_clear_config_network(conf);
        if (conf->lsm_aa_profile)
index 563109c5e28824a476b11c324d723fbc09b2447a..06d3e234da2e79eb02ea9753812f6f1a02bdb6ac 100644 (file)
@@ -356,6 +356,9 @@ struct lxc_conf {
        /* text representation of the config file */
        char *unexpanded_config;
        size_t unexpanded_len, unexpanded_alloced;
+
+       /* init command */
+       char *init_cmd;
 };
 
 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
index 886f8a1130014dffd929f0d98b0f83e3452f2b43..83dab05cad5d24a11a6b153785498a6691204f78 100644 (file)
@@ -101,6 +101,7 @@ static int config_stopsignal(const char *, const char *, struct lxc_conf *);
 static int config_start(const char *, const char *, struct lxc_conf *);
 static int config_group(const char *, const char *, struct lxc_conf *);
 static int config_environment(const char *, const char *, struct lxc_conf *);
+static int config_init_cmd(const char *, const char *, struct lxc_conf *);
 
 static struct lxc_config_t config[] = {
 
@@ -162,6 +163,7 @@ static struct lxc_config_t config[] = {
        { "lxc.start.order",          config_start                },
        { "lxc.group",                config_group                },
        { "lxc.environment",          config_environment          },
+       { "lxc.init_cmd",             config_init_cmd             },
 };
 
 struct signame {
@@ -965,6 +967,12 @@ static int config_seccomp(const char *key, const char *value,
        return config_path_item(&lxc_conf->seccomp, value);
 }
 
+static int config_init_cmd(const char *key, const char *value,
+                                struct lxc_conf *lxc_conf)
+{
+       return config_path_item(&lxc_conf->init_cmd, value);
+}
+
 static int config_hook(const char *key, const char *value,
                                 struct lxc_conf *lxc_conf)
 {
@@ -2327,6 +2335,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
                v = c->seccomp;
        else if (strcmp(key, "lxc.environment") == 0)
                return lxc_get_item_environment(c, retv, inlen);
+       else if (strcmp(key, "lxc.init_cmd") == 0)
+               v = c->init_cmd;
        else return -1;
 
        if (!v)
index d0e3bfa315655003e80f69fc041951b9ab53e155..db25b4871fd000688aad020f78133f217a50f7ff 100644 (file)
@@ -330,10 +330,6 @@ int main(int argc, char *argv[])
        struct lxc_container **containers = NULL;
        struct lxc_list **c_groups_lists = NULL;
        struct lxc_list *cmd_group;
-       char *const default_start_args[] = {
-               "/sbin/init",
-               NULL,
-       };
 
        if (lxc_arguments_parse(&my_args, argc, argv))
                return 1;
@@ -470,7 +466,7 @@ int main(int argc, char *argv[])
                                                printf("%s %d\n", c->name,
                                                       get_config_integer(c, "lxc.start.delay"));
                                        else {
-                                               if (!c->start(c, 0, default_start_args))
+                                               if (!c->start(c, 0, NULL))
                                                        fprintf(stderr, "Error starting container: %s\n", c->name);
                                                else
                                                        sleep(get_config_integer(c, "lxc.start.delay"));
index 874bb9e4daefbdd7a3de3bae096a750edeaf86b2..006ffc42a959dc8e0b645e694a5db4c64b178874 100644 (file)
@@ -336,7 +336,10 @@ int main(int argc, char *argv[])
        if (my_args.close_all_fds)
                c->want_close_all_fds(c, true);
 
-       err = c->start(c, 0, args) ? 0 : 1;
+       if (args == default_args)
+               err = c->start(c, 0, NULL) ? 0 : 1;
+       else
+               err = c->start(c, 0, args) ? 0 : 1;
 
        if (err) {
                ERROR("The container failed to start.");
index 2372b197f8770d541c3ffa2451b2a0f4eacb1ba4..406cead1590f4be0f4cfc6fe06580b62f22b8b81 100644 (file)
@@ -555,6 +555,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
                "/sbin/init",
                NULL,
        };
+       char *init_cmd[2];
 
        /* container exists */
        if (!c)
@@ -591,8 +592,15 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
                return ret == 0 ? true : false;
        }
 
-       if (!argv)
-               argv = default_args;
+       if (!argv) {
+               if (conf->init_cmd) {
+                       init_cmd[0] = conf->init_cmd;
+                       init_cmd[1] = NULL;
+                       argv = init_cmd;
+               }
+               else
+                       argv = default_args;
+       }
 
        /*
        * say, I'm not sure - what locks do we want here?  Any?