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>
* @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
lxc_error(args, "missing command to execute !");
return -1;
}
+
return 0;
}
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);
}
{
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
};
\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,
if (!memcmp(tios, ¤t_tios, sizeof(*tios)))
return 0;
-
oldhandler = signal(SIGTTOU, SIG_IGN);
ret = tcsetattr(0, TCSADRAIN, tios);
if (ret)
save_tty(&tios);
- err = lxc_start(my_args.name, args);
+ err = lxc_start(my_args.name, args, my_args.rcfile);
restore_tty(&tios);
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];
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,
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;
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[]);