Commit b71febc4 authored by mdempsky's avatar mdempsky Committed by Commit bot

sandbox: use waitpid consistently

The BMM PNaCl toolchain doesn't currently support waitid.  Arguably it
should because it's in POSIX, but the userland/Linux signal ABI
mismatch makes it non-trivial because of the siginfo_t.  Since we
don't need the siginfo_t anyway, we can just use waitpid instead.

While here, use WIFEXITED and WEXITSTATUS for interpreting status
instead of directly comparing it to the expected exit code.

Review URL: https://codereview.chromium.org/928963003

Cr-Commit-Position: refs/heads/master@{#317080}
parent 30728015
...@@ -114,7 +114,7 @@ bool ChrootToSafeEmptyDir() { ...@@ -114,7 +114,7 @@ bool ChrootToSafeEmptyDir() {
int status = -1; int status = -1;
PCHECK(HANDLE_EINTR(waitpid(pid, &status, 0)) == pid); PCHECK(HANDLE_EINTR(waitpid(pid, &status, 0)) == pid);
return kExitSuccess == status; return WIFEXITED(status) && WEXITSTATUS(status) == kExitSuccess;
} }
// CHECK() that an attempt to move to a new user namespace raised an expected // CHECK() that an attempt to move to a new user namespace raised an expected
...@@ -174,12 +174,14 @@ bool Credentials::CanCreateProcessInNewUserNS() { ...@@ -174,12 +174,14 @@ bool Credentials::CanCreateProcessInNewUserNS() {
// have disappeared. Make sure to not do anything in the child, as this is a // have disappeared. Make sure to not do anything in the child, as this is a
// fragile execution environment. // fragile execution environment.
if (pid == 0) { if (pid == 0) {
_exit(0); _exit(kExitSuccess);
} }
// Always reap the child. // Always reap the child.
siginfo_t infop; int status = -1;
PCHECK(0 == HANDLE_EINTR(waitid(P_PID, pid, &infop, WEXITED))); PCHECK(HANDLE_EINTR(waitpid(pid, &status, 0)) == pid);
CHECK(WIFEXITED(status));
CHECK_EQ(kExitSuccess, WEXITSTATUS(status));
// clone(2) succeeded, we can use CLONE_NEWUSER. // clone(2) succeeded, we can use CLONE_NEWUSER.
return true; return true;
......
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