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[])
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;
}
}
......
......@@ -33,6 +33,7 @@
#define _GNU_SOURCE
#include <getopt.h>
#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;
}
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