]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Allows a container to run without previous creation
authorDaniel Lezcaon <daniel.lezcano@free.fr>
Fri, 13 Nov 2009 10:48:29 +0000 (11:48 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Fri, 13 Nov 2009 10:48:29 +0000 (11:48 +0100)
When a container was created, its configuration is used.
When a container was not created, the configuration specified in
the command line is used, if not configuration file is used,
default values are used.

That allows to create 'volatile' container, like tmp files.
It is useful for example to spawn different container with the
same generic configuration file. That let the user to have its own
repository of configuration files.

And, more important, that fix temporary created container with
lxc-execute to be not deleted when the host crash or the command
is killed.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/lxc.h
src/lxc/lxc_execute.c
src/lxc/lxc_start.c
src/lxc/start.c
src/lxc/start.h

index 4693f43f0c37a519f87d12d9263e019ab16a1c9c..95e2347ba122588c8c4440594188292224b9c3ac 100644 (file)
@@ -71,7 +71,7 @@ extern int lxc_destroy(const char *name);
  * @argv     : an array of char * corresponding to the commande line
  * Returns 0 on sucess, < 0 otherwise
  */
-extern int lxc_start(const char *name, char *const argv[]);
+extern int lxc_start(const char *name, char *const argv[], const char *rcfile);
 
 /*
  * Stop the container previously started with lxc_start, all
index 226c6ec8ca6aa5758311d0b1ca5472d47579d8bf..746cb4e8bb6558ed257e3c30cd4b9db105fc8346 100644 (file)
@@ -44,6 +44,7 @@ static int my_checker(const struct lxc_arguments* args)
                lxc_error(args, "missing command to execute !");
                return -1;
        }
+
        return 0;
 }
 
@@ -79,39 +80,18 @@ Options :\n\
 int main(int argc, char *argv[])
 {
        static char **args;
-       char path[MAXPATHLEN];
-       int autodestroy = 0;
-       int ret = -1;
 
        if (lxc_arguments_parse(&my_args, argc, argv))
-               goto out;
+               return -1;
 
        if (lxc_log_init(my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet))
-               goto out;
-
-       /* the container is not created, let's create it */
-       snprintf(path, MAXPATHLEN, LXCPATH "/%s", my_args.name);
-       if (access(path, R_OK)) {
-               if (lxc_create(my_args.name, my_args.rcfile))
-                       goto out;
-               autodestroy = 1;
-       }
+               return -1;
 
        args = lxc_arguments_dup(LXCLIBEXECDIR "/lxc-init", &my_args);
        if (!args)
-               goto out;
-
-       ret = lxc_start(my_args.name, args);
-out:
-       if (autodestroy) {
-               if (lxc_destroy(my_args.name)) {
-                       ERROR("failed to destroy '%s'", my_args.name);
-                       if (!ret)
-                               ret = -1;
-               }
-       }
+               return -1;
 
-       return ret;
+       return lxc_start(my_args.name, args, my_args.rcfile);
 }
 
index 1d3c81953e102e512c22993dcaf6d091a7ec4672..ffeb66baebcc0cc346c85f3ee5525d8629abf168 100644 (file)
@@ -47,12 +47,14 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 {
        switch (c) {
        case 'd': args->daemonize = 1; break;
+       case 'f': args->rcfile = arg; break;
        }
        return 0;
 }
 
 static const struct option my_longopts[] = {
        {"daemon", no_argument, 0, 'd'},
+       {"rcfile", required_argument, 0, 'f'},
        LXC_COMMON_OPTIONS
 };
 
@@ -65,7 +67,8 @@ lxc-start start COMMAND in specified container NAME\n\
 \n\
 Options :\n\
   -n, --name=NAME      NAME for name of the container\n\
-  -d, --daemon         daemonize the container",
+  -d, --daemon         daemonize the container\n\
+  -f, --rcfile=FILE    Load configuration file FILE\n",
        .options   = my_longopts,
        .parser    = my_parser,
        .checker   = NULL,
@@ -102,7 +105,6 @@ static int restore_tty(struct termios *tios)
        if (!memcmp(tios, &current_tios, sizeof(*tios)))
                return 0;
 
-
        oldhandler = signal(SIGTTOU, SIG_IGN);
        ret = tcsetattr(0, TCSADRAIN, tios);
        if (ret)
@@ -163,7 +165,7 @@ int main(int argc, char *argv[])
 
        save_tty(&tios);
 
-       err = lxc_start(my_args.name, args);
+       err = lxc_start(my_args.name, args, my_args.rcfile);
 
        restore_tty(&tios);
 
index dd81fccbdb1923a160594f6e75201d5a6f7c0b49..90300719cdb12e57ba7614c662135b9366481686 100644 (file)
@@ -235,7 +235,7 @@ static int console_init(char *console, size_t size)
        return 0;
 }
 
-struct lxc_handler *lxc_init(const char *name)
+struct lxc_handler *lxc_init(const char *name, const char *rcfile)
 {
        struct lxc_handler *handler;
        char path[MAXPATHLEN];
@@ -257,11 +257,14 @@ struct lxc_handler *lxc_init(const char *name)
                goto out_aborting;
        }
 
-       snprintf(path, sizeof(path), LXCPATH "/%s/config", name);
-
-       if (!access(path, F_OK) && lxc_config_read(path, &handler->conf)) {
-               ERROR("failed to read the configuration file");
+       if (rcfile && access(path, F_OK)) {
+               ERROR("failed to access rcfile");
                goto out_aborting;
+
+               if (lxc_config_read(path, &handler->conf)) {
+                       ERROR("failed to read the configuration file");
+                       goto out_aborting;
+               }
        }
 
        if (console_init(handler->conf.console,
@@ -488,13 +491,13 @@ out_abort:
        goto out_close;
 }
 
-int lxc_start(const char *name, char *const argv[])
+int lxc_start(const char *name, char *const argv[], const char *rcfile)
 {
        struct lxc_handler *handler;
        int err = -1;
        int status;
 
-       handler = lxc_init(name);
+       handler = lxc_init(name, rcfile);
        if (!handler) {
                ERROR("failed to initialize the container");
                return -1;
index 8b46b66b40004c672fa02ead4e0a32482a070a84..03d8762eed51294ef6bf2a65a8189d9e5b5a8ed2 100644 (file)
@@ -32,7 +32,7 @@ struct lxc_handler {
        struct lxc_conf conf;
 };
 
-extern struct lxc_handler *lxc_init(const char *name);
+extern struct lxc_handler *lxc_init(const char *name, const char *rcfile);
 extern int lxc_spawn(const char *name, struct lxc_handler *handler,
                     char *const argv[]);