]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc-create to return 255 in case of error
authorMichel Normand <normand@fr.ibm.com>
Mon, 18 May 2009 20:27:35 +0000 (22:27 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Mon, 18 May 2009 20:27:35 +0000 (22:27 +0200)
to have same exit code for all lxc commands

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/create.c
src/lxc/lxc_create.c

index ae5d1e8a54bbf51d624ed21f5d5afcffbded59cf..64746b362cf5145610473ea09582a6d8c77fcd13 100644 (file)
@@ -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;
        }
index 57dc41e8535dba92c53ac0f538e7e757b54192cf..9d23aa9c3a01aeba2f207a3e15318bec8653f395 100644 (file)
@@ -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);
 }