From: Michel Normand Date: Mon, 18 May 2009 20:27:35 +0000 (+0200) Subject: lxc-execute to report exit code of started application X-Git-Tag: lxc_0_6_3~83 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b0ed5e6423ca1f0b74f8c0ad12901c845e3ffbd1;p=thirdparty%2Flxc.git lxc-execute to report exit code of started application The exit code of the application as reported by lxc-execute is: 0-126 exit code of the application itself 128+n signal n received by the application 255 lxc error Note that this is the same type of changes as done for lxc-start command line. Signed-off-by: Michel Normand Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c index eb7ef9cbd..aea7a3c56 100644 --- a/src/lxc/lxc_execute.c +++ b/src/lxc/lxc_execute.c @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) int opt; int nbargs = 0; int autodestroy = 0; - int ret = 1; + int ret = -1; struct lxc_conf lxc_conf; if (lxc_arguments_parse(&my_args, argc, argv)) @@ -131,17 +131,12 @@ int main(int argc, char *argv[]) args[nbargs++] = my_args.argv[opt]; ret = lxc_start(my_args.name, args); - if (ret) { - ERROR("failed to start '%s'", my_args.name); - goto out; - } - - ret = 0; out: if (autodestroy) { if (lxc_destroy(my_args.name)) { ERROR("failed to destroy '%s'", my_args.name); - ret = 1; + if (!ret) + ret = -1; } } diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 5b00d147a..964730706 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -33,6 +33,7 @@ #define _GNU_SOURCE #include #include "log.h" +#include "error.h" lxc_log_define(lxc_init, lxc); @@ -55,6 +56,7 @@ int main(int argc, char *argv[]) { pid_t pid; int nbargs = 0; + int err = -1; char **aargv; while (1) { @@ -66,17 +68,17 @@ int main(int argc, char *argv[]) case 'o': log_file = optarg; break; case 'l': log_priority = optarg; break; case '?': - exit(1); + exit(err); } nbargs++; } if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet)) - exit(1); + exit(err); if (!argv[optind]) { ERROR("missing command to launch"); - exit(1); + exit(err); } aargv = &argv[optind]; @@ -85,36 +87,41 @@ int main(int argc, char *argv[]) pid = fork(); if (pid < 0) - exit(1); + exit(err); if (!pid) { if (mount_sysfs && mount("sysfs", "/sys", "sysfs", 0, NULL)) { ERROR("failed to mount '/sys' : %s", strerror(errno)); - exit(1); + exit(err); } if (mount_procfs && mount("proc", "/proc", "proc", 0, NULL)) { ERROR("failed to mount '/proc' : %s", strerror(errno)); - exit(1); + exit(err); } execvp(aargv[0], aargv); ERROR("failed to exec: '%s' : %s", aargv[0], strerror(errno)); - exit(1); + exit(err); } for (;;) { int status; - if (wait(&status) < 0) { + pid_t waited_pid; + + waited_pid = wait(&status); + if (waited_pid < 0) { if (errno == ECHILD) - exit(0); + goto out; if (errno == EINTR) continue; - ERROR("failed to wait child"); - return 1; + ERROR("failed to wait child : %s", strerror(errno)); + goto out; + } else { + err = lxc_error_set_and_log(waited_pid, status); } } - - return 0; +out: + return err; }