Commit 7f830613 by Michel Normand Committed by Daniel Lezcano

lxc-create to return 255 in case of error

to have same exit code for all lxc commands Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 23075e69
......@@ -61,14 +61,14 @@ static int create_lxc_directory(const char *dirname)
if (mkdir(LXCPATH, 0755) && errno != EEXIST) {
SYSERROR("failed to create %s directory", LXCPATH);
return -errno;
return -1;
}
sprintf(path, LXCPATH "/%s", dirname);
snprintf(path, MAXPATHLEN, LXCPATH "/%s", dirname);
if (mkdir(path, 0755)) {
SYSERROR("failed to create %s directory", path);
return -errno;
return -1;
}
return 0;
......@@ -78,7 +78,7 @@ static int remove_lxc_directory(const char *dirname)
{
char path[MAXPATHLEN];
sprintf(path, LXCPATH "/%s", dirname);
snprintf(path, MAXPATHLEN, LXCPATH "/%s", dirname);
if (rmdir(path)) {
SYSERROR("failed to remove %s directory", path);
......@@ -97,18 +97,15 @@ static int remove_lxc_directory(const char *dirname)
int lxc_create(const char *name, struct lxc_conf *conf)
{
int lock, err;
int lock, err = -1;
err = create_lxc_directory(name);
if (err < 0)
return err == -EEXIST ?
-LXC_ERROR_EEXIST : LXC_ERROR_INTERNAL;
if (create_lxc_directory(name))
return err;
lock = lxc_get_lock(name);
if (lock < 0)
return -LXC_ERROR_LOCK;
return err;
err = LXC_ERROR_INTERNAL;
if (lxc_mkstate(name)) {
ERROR("failed to create the state file for %s", name);
goto err;
......@@ -119,8 +116,7 @@ int lxc_create(const char *name, struct lxc_conf *conf)
goto err_state;
}
err = lxc_configure(name, conf);
if (err) {
if (lxc_configure(name, conf)) {
ERROR("failed to set configuration for %s", name);
goto err_state;
}
......
......@@ -70,22 +70,18 @@ int main(int argc, char *argv[])
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
return 1;
return -1;
if (lxc_log_init(my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet))
return 1;
return -1;
if (lxc_conf_init(&lxc_conf))
return 1;
return -1;
if (my_args.rcfile && lxc_config_read(my_args.rcfile, &lxc_conf))
return 1;
return -1;
ret = lxc_create(my_args.name, &lxc_conf);
if (ret)
return 1;
return 0;
return lxc_create(my_args.name, &lxc_conf);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment