Commit 37c3dfc9 by Michel Normand Committed by Daniel Lezcano

lxc-execute to return exit code of its child not others

lxc-execute has to return the exit code of it's child not others as today's code would return the exit code of the last child. We need to track the first process we launched and store its exit status when it exits. In order to avoid to detect the exit of this pid several time if the pids number wrap, we put an extra flag saying the process group is orhpan. Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 7cbfc4e4
...@@ -106,8 +106,10 @@ int main(int argc, char *argv[]) ...@@ -106,8 +106,10 @@ int main(int argc, char *argv[])
exit(err); exit(err);
} }
err = 0;
for (;;) { for (;;) {
int status; int status;
int orphan = 0;
pid_t waited_pid; pid_t waited_pid;
waited_pid = wait(&status); waited_pid = wait(&status);
...@@ -118,9 +120,16 @@ int main(int argc, char *argv[]) ...@@ -118,9 +120,16 @@ int main(int argc, char *argv[])
continue; continue;
ERROR("failed to wait child : %s", strerror(errno)); ERROR("failed to wait child : %s", strerror(errno));
goto out; goto out;
} else {
err = lxc_error_set_and_log(waited_pid, status);
} }
/*
* keep the exit code of started application (not wrapped pid)
* and continue to wait for the end of the orphan group.
*/
if ((waited_pid != pid) || (orphan ==1))
continue;
orphan = 1;
err = lxc_error_set_and_log(waited_pid, status);
} }
out: out:
return err; 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