]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Return a lxc-error for creation and starting
authordlezcano <dlezcano>
Mon, 17 Nov 2008 18:22:29 +0000 (18:22 +0000)
committerdlezcano <dlezcano>
Mon, 17 Nov 2008 18:22:29 +0000 (18:22 +0000)
From: Daniel Lezcano <dlezcano@fr.ibm.com>

Return a lxc-error when for the lxc_configure and lxc_setup function.

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

index ef7fa996d04b10542927244d86aabab5dc6ac38d..32aa4f64add5011a0c7949bb06d5024c673f674d 100644 (file)
@@ -112,7 +112,8 @@ int lxc_create(const char *name, struct lxc_conf *conf)
                goto err_state;
        }
 
-       if (lxc_configure(name, conf)) {
+       err = lxc_configure(name, conf);
+       if (err) {
                lxc_log_error("failed to set configuration for %s", name);
                goto err_state;
        }
index 1955623524ddc80e721e0f1c803feeaabed5c8b5..e0661ef9df6ecf6ddc2be815110a79389ef743e8 100644 (file)
 #include <net/if.h>
 #include <libgen.h>
 
+#include "network.h"
+#include "error.h"
+
 #include <lxc/lxc.h>
-#include <network.h>
+
 
 #define MAXHWLEN    18
 #define MAXINDEXLEN 20
@@ -1030,27 +1033,27 @@ int lxc_configure(const char *name, struct lxc_conf *conf)
 
        if (conf->utsname && configure_utsname(name, conf->utsname)) {
                lxc_log_error("failed to configure the utsname");
-               return -1;
+               return -LXC_ERROR_CONF_UTSNAME;
        }
 
        if (configure_cgroup(name, &conf->cgroup)) {
                lxc_log_error("failed to configure the control group");
-               return -1;
+               return -LXC_ERROR_CONF_CGROUP;
        }
 
        if (configure_network(name, &conf->networks)) {
                lxc_log_error("failed to configure the network");
-               return -1;
+               return -LXC_ERROR_CONF_NETWORK;
        }
 
        if (conf->rootfs && configure_rootfs(name, conf->rootfs)) {
                lxc_log_error("failed to configure the rootfs");
-               return -1;
+               return -LXC_ERROR_CONF_ROOTFS;
        }
 
        if (conf->fstab && configure_mount(name, conf->fstab)) {
                lxc_log_error("failed to configure the mount points");
-               return -1;
+               return -LXC_ERROR_CONF_MOUNT;
        }
 
        return 0;
@@ -1372,27 +1375,27 @@ int lxc_setup(const char *name)
 {
        if (conf_has_utsname(name) && setup_utsname(name)) {
                lxc_log_error("failed to setup the utsname for '%s'", name);
-               return -1;
+               return -LXC_ERROR_SETUP_UTSNAME;
        }
 
        if (conf_has_network(name) && setup_network(name)) {
                lxc_log_error("failed to setup the network for '%s'", name);
-               return -1;
+               return -LXC_ERROR_SETUP_NETWORK;
        }
 
        if (conf_has_cgroup(name) && setup_cgroup(name)) {
                lxc_log_error("failed to setup the cgroups for '%s'", name);
-               return -1;
+               return -LXC_ERROR_SETUP_CGROUP;
        }
 
        if (conf_has_fstab(name) && setup_mount(name)) {
                lxc_log_error("failed to setup the mount points for '%s'", name);
-               return -1;
+               return -LXC_ERROR_SETUP_MOUNT;
        }
 
        if (conf_has_rootfs(name) && setup_rootfs(name)) {
                lxc_log_error("failed to set rootfs for '%s'", name);
-               return -1;
+               return -LXC_ERROR_SETUP_ROOTFS;
        }
 
        return 0;
index 8d056fecf5d8a719255ea4017ed0629d380caaab..f0bcb36583d1e3549a14bc41136a825207736608 100644 (file)
@@ -55,10 +55,13 @@ int lxc_start(const char *name, char *argv[])
        int clone_flags;
 
        lock = lxc_get_lock(name);
-       if (lock < 0)
-               return lock == -EWOULDBLOCK ? 
-                       -LXC_ERROR_BUSY : 
-                       -LXC_ERROR_LOCK;
+       if (lock < 0) {
+               if (lock == -EWOULDBLOCK)
+                       return -LXC_ERROR_BUSY;
+               if (lock == -ENOENT)
+                       return -LXC_ERROR_NOT_FOUND;
+               return -LXC_ERROR_LOCK;
+       }
 
        /* Begin the set the state to STARTING*/
        if (lxc_setstate(name, STARTING)) {
@@ -71,7 +74,6 @@ int lxc_start(const char *name, char *argv[])
                goto out;
        }
 
-
        /* Synchro socketpair */
        if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
                lxc_log_syserror("failed to create communication socketpair");
@@ -115,9 +117,10 @@ int lxc_start(const char *name, char *argv[])
                }
 
                /* Setup the container, ip, names, utsname, ... */
-               if (lxc_setup(name)) {
+               err = lxc_setup(name);
+               if (err) {
                        lxc_log_error("failed to setup the container");
-                       if (write(sv[0], &sync, sizeof(sync)) < 0)
+                       if (write(sv[0], &err, sizeof(err)) < 0)
                                lxc_log_syserror("failed to write the socket");
                        goto out_child;
                }
@@ -136,11 +139,11 @@ int lxc_start(const char *name, char *argv[])
                lxc_log_syserror("failed to exec %s", argv[0]);
 
                /* If the exec fails, tell that to our father */
-               if (write(sv[0], &sync, sizeof(sync)) < 0)
+               if (write(sv[0], &err, sizeof(err)) < 0)
                        lxc_log_syserror("failed to write the socket");
                
        out_child:
-               exit(1);
+               exit(err);
        }
 
        close(sv[0]);
@@ -174,7 +177,8 @@ int lxc_start(const char *name, char *argv[])
        }
 
        if (err > 0) {
-               lxc_log_error("something went wrong with %d", pid);
+               err = sync;
+               printf("error value is %d\n", err);
                /* TODO : check status etc ... */
                waitpid(pid, NULL, 0);
                goto err_child_failed;