waitpid() on the child process when changing namespaces
This allows upstart to wait for the process as if it was the same one called.
Otherwise, we lose the process id and upstart assumes everything is over.
"expect fork" does not handle this properly.
TEST=manual check: /sbin/minijail --namespace-vfs -- /bin/bash -c 'sleep 1'
BUG=none
Review URL: http://codereview.chromium.org/1570004
diff --git a/env.cc b/env.cc
index 5ee0667..bd6eb03 100644
--- a/env.cc
+++ b/env.cc
@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <base/logging.h>
@@ -203,9 +204,20 @@
return false;
}
if (pid) {
+ // We want to wait on the child pid to ensure that pid-tracking code
+ // isn't completely broken.
+ int status = 0;
+ waitpid(pid, &status, 0);
// Kill the original process without atexit handlers.
- DLOG(INFO) << "original process death:" << pid;
- _exit(0);
+ DLOG(INFO) << "jailed process death:" << pid;
+ if (WIFEXITED(status)) {
+ _exit(WEXITSTATUS(status));
+ }
+ if (WIFSIGNALED(status)) {
+ _exit(WTERMSIG(status));
+ }
+ DLOG(INFO) << "unknown terminal condition for child";
+ _exit(1);
}
DLOG(INFO) << "Success: " << getpid();
return true;