Unverified Commit 6f5d4e2e by Tycho Andersen Committed by Christian Brauner

lxc.init: correctly exit with the app's error code

Based on the comments in the code (and the have_status flag), the intent here (and IMO, the desired behavior) should be for init.lxc to propagate the actual exit code from the real application process up through. Otherwise, it is swallowed and nobody can access it. The bug being fixed here is that ret held the correct exit code, but when it went around the loop again (to wait for other children) ret is clobbered. Let's save the desired exit status somewhere else, so it can't get clobbered, and we propagate things correctly. Signed-off-by: 's avatarTycho Andersen <tycho@tycho.ws>
parent f4ce67ec
...@@ -199,7 +199,7 @@ int main(int argc, char *argv[]) ...@@ -199,7 +199,7 @@ int main(int argc, char *argv[])
struct sigaction act; struct sigaction act;
struct lxc_log log; struct lxc_log log;
sigset_t mask, omask; sigset_t mask, omask;
int have_status = 0, shutdown = 0; int have_status = 0, exit_with = 1, shutdown = 0;
if (arguments_parse(&my_args, argc, argv)) if (arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -412,14 +412,14 @@ int main(int argc, char *argv[]) ...@@ -412,14 +412,14 @@ int main(int argc, char *argv[])
* pid) and continue to wait for the end of the orphan group. * pid) and continue to wait for the end of the orphan group.
*/ */
if (waited_pid == pid && !have_status) { if (waited_pid == pid && !have_status) {
ret = lxc_error_set_and_log(waited_pid, status); exit_with = lxc_error_set_and_log(waited_pid, status);
have_status = 1; have_status = 1;
} }
} }
out: out:
if (ret < 0) if (ret < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
exit(ret); exit(exit_with);
} }
static void print_usage(const struct option longopts[]) static void print_usage(const struct option longopts[])
......
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