Commit b0ed5e64 by Michel Normand Committed by Daniel Lezcano

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: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 8559e703
...@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) ...@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
int opt; int opt;
int nbargs = 0; int nbargs = 0;
int autodestroy = 0; int autodestroy = 0;
int ret = 1; int ret = -1;
struct lxc_conf lxc_conf; struct lxc_conf lxc_conf;
if (lxc_arguments_parse(&my_args, argc, argv)) if (lxc_arguments_parse(&my_args, argc, argv))
...@@ -131,17 +131,12 @@ int main(int argc, char *argv[]) ...@@ -131,17 +131,12 @@ int main(int argc, char *argv[])
args[nbargs++] = my_args.argv[opt]; args[nbargs++] = my_args.argv[opt];
ret = lxc_start(my_args.name, args); ret = lxc_start(my_args.name, args);
if (ret) {
ERROR("failed to start '%s'", my_args.name);
goto out;
}
ret = 0;
out: out:
if (autodestroy) { if (autodestroy) {
if (lxc_destroy(my_args.name)) { if (lxc_destroy(my_args.name)) {
ERROR("failed to destroy '%s'", my_args.name); ERROR("failed to destroy '%s'", my_args.name);
ret = 1; if (!ret)
ret = -1;
} }
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <getopt.h> #include <getopt.h>
#include "log.h" #include "log.h"
#include "error.h"
lxc_log_define(lxc_init, lxc); lxc_log_define(lxc_init, lxc);
...@@ -55,6 +56,7 @@ int main(int argc, char *argv[]) ...@@ -55,6 +56,7 @@ int main(int argc, char *argv[])
{ {
pid_t pid; pid_t pid;
int nbargs = 0; int nbargs = 0;
int err = -1;
char **aargv; char **aargv;
while (1) { while (1) {
...@@ -66,17 +68,17 @@ int main(int argc, char *argv[]) ...@@ -66,17 +68,17 @@ int main(int argc, char *argv[])
case 'o': log_file = optarg; break; case 'o': log_file = optarg; break;
case 'l': log_priority = optarg; break; case 'l': log_priority = optarg; break;
case '?': case '?':
exit(1); exit(err);
} }
nbargs++; nbargs++;
} }
if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet)) if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
exit(1); exit(err);
if (!argv[optind]) { if (!argv[optind]) {
ERROR("missing command to launch"); ERROR("missing command to launch");
exit(1); exit(err);
} }
aargv = &argv[optind]; aargv = &argv[optind];
...@@ -85,36 +87,41 @@ int main(int argc, char *argv[]) ...@@ -85,36 +87,41 @@ int main(int argc, char *argv[])
pid = fork(); pid = fork();
if (pid < 0) if (pid < 0)
exit(1); exit(err);
if (!pid) { if (!pid) {
if (mount_sysfs && mount("sysfs", "/sys", "sysfs", 0, NULL)) { if (mount_sysfs && mount("sysfs", "/sys", "sysfs", 0, NULL)) {
ERROR("failed to mount '/sys' : %s", strerror(errno)); ERROR("failed to mount '/sys' : %s", strerror(errno));
exit(1); exit(err);
} }
if (mount_procfs && mount("proc", "/proc", "proc", 0, NULL)) { if (mount_procfs && mount("proc", "/proc", "proc", 0, NULL)) {
ERROR("failed to mount '/proc' : %s", strerror(errno)); ERROR("failed to mount '/proc' : %s", strerror(errno));
exit(1); exit(err);
} }
execvp(aargv[0], aargv); execvp(aargv[0], aargv);
ERROR("failed to exec: '%s' : %s", aargv[0], strerror(errno)); ERROR("failed to exec: '%s' : %s", aargv[0], strerror(errno));
exit(1); exit(err);
} }
for (;;) { for (;;) {
int status; int status;
if (wait(&status) < 0) { pid_t waited_pid;
waited_pid = wait(&status);
if (waited_pid < 0) {
if (errno == ECHILD) if (errno == ECHILD)
exit(0); goto out;
if (errno == EINTR) if (errno == EINTR)
continue; continue;
ERROR("failed to wait child"); ERROR("failed to wait child : %s", strerror(errno));
return 1; goto out;
} else {
err = lxc_error_set_and_log(waited_pid, status);
} }
} }
out:
return 0; return err;
} }
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