if (args->quiet)
nbargs += 1;
- argv = malloc(nbargs * sizeof(*argv));
+ argv = malloc((nbargs + 1) * sizeof(*argv));
if (!argv)
return NULL;
int lxc_conf_init(struct lxc_conf *conf)
{
- conf->rcfile = NULL;
conf->rootfs = NULL;
conf->fstab = NULL;
conf->utsname = NULL;
* @utsname : the container utsname
*/
struct lxc_conf {
- const char *rcfile;
char *rootfs;
char *fstab;
int tty;
{
char buffer[MAXPATHLEN];
- conf->rcfile = file;
-
return lxc_file_for_each_line(file, parse_line, buffer,
sizeof(buffer), conf);
}
static int copy_config_file(const char *name, const char *file)
{
char *dst;
- int ret;
+ int ret = -1;
if (!asprintf(&dst, LXCPATH "/%s/config", name)) {
ERROR("failed to allocate memory");
ret = lxc_copy_file(file, dst);
if (ret)
ERROR("failed to copy '%s' to '%s'", file, dst);
+
free(dst);
return ret;
}
-int lxc_create(const char *name, struct lxc_conf *conf)
+int lxc_create(const char *name, const char *confile)
{
int lock, err = -1;
if (create_lxc_directory(name))
return err;
+ if (!confile)
+ return 0;
+
lock = lxc_get_lock(name);
if (lock < 0)
goto err;
- if (conf->rcfile && copy_config_file(name, conf->rcfile)) {
+ if (copy_config_file(name, confile)) {
ERROR("failed to copy the configuration file");
goto err_state;
}
* @conf : the configuration data for the container
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_create(const char *name, struct lxc_conf *conf);
+extern int lxc_create(const char *name, const char *confile);
/*
* Destroy the container object. Removes the files into the /lxc/<name>
return -1;
}
- if (lxc_create(my_args.name, &lxc_conf)) {
+ if (lxc_create(my_args.name, my_args.rcfile)) {
ERROR("failed to create the container");
return -1;
}
char path[MAXPATHLEN];
int autodestroy = 0;
int ret = -1;
- struct lxc_conf lxc_conf;
if (lxc_arguments_parse(&my_args, argc, argv))
goto out;
my_args.progname, my_args.quiet))
goto out;
- if (lxc_conf_init(&lxc_conf))
- goto out;
-
- if (my_args.rcfile && lxc_config_read(my_args.rcfile, &lxc_conf))
- 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, &lxc_conf))
+ if (lxc_create(my_args.name, my_args.rcfile))
goto out;
autodestroy = 1;
}
snprintf(path, sizeof(path), LXCPATH "/%s/config", name);
- if (!access(path, F_OK)) {
-
- if (lxc_config_read(path, &handler->conf)) {
- ERROR("failed to read the configuration file");
- goto out_aborting;
- }
+ if (!access(path, F_OK) && lxc_config_read(path, &handler->conf)) {
+ ERROR("failed to read the configuration file");
+ goto out_aborting;
}
- if (console_init(handler->conf.console, sizeof(handler->conf.console))) {
+ if (console_init(handler->conf.console,
+ sizeof(handler->conf.console))) {
ERROR("failed to initialize the console");
goto out_aborting;
}
return 1;
}
- if (lxc_create(name, &lxc_conf)) {
+ if (lxc_create(name, file)) {
fprintf(stderr, "failed to create <%s>\n", name);
return 1;
}
lxc_conf_init(&lxc_conf);
- if (lxc_create(name, &lxc_conf)) {
+ if (lxc_create(name, NULL)) {
fprintf(stderr, "failed to create the container %s\n", name);
return 1;
}