Commit e5bda9ee by dlezcano

Return a lxc-error for creation and starting

From: Daniel Lezcano <dlezcano@fr.ibm.com> Return a lxc-error when for the lxc_configure and lxc_setup function. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 1f3da8f8
......@@ -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;
}
......
......@@ -44,8 +44,11 @@
#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;
......
......@@ -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;
......
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