Commit 86ed44e0 authored by Tom Sepez's avatar Tom Sepez Committed by Commit Bot

Handle error return from zygote recvmsg call.

This trips a check far away from the actual issue. The CHECK is too
strong and prevents executing the error handling path beneath it.

Shuffle a few blocks and comments around so that the flow makes
more sense and is easier to read, and initial fork failures are
caught earlier.

Bug: 835778
Change-Id: I46b960f9fd1095f5fc5224bf9cc80703e8fc325f
Reviewed-on: https://chromium-review.googlesource.com/1030876
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554949}
parent e503c603
...@@ -438,6 +438,8 @@ int Zygote::ForkWithRealPid(const std::string& process_type, ...@@ -438,6 +438,8 @@ int Zygote::ForkWithRealPid(const std::string& process_type,
} }
if (pid == 0) { if (pid == 0) {
// In the child process.
// If the process is the init process inside a PID namespace, it must have // If the process is the init process inside a PID namespace, it must have
// explicit signal handlers. // explicit signal handlers.
if (getpid() == 1) { if (getpid() == 1) {
...@@ -449,7 +451,6 @@ int Zygote::ForkWithRealPid(const std::string& process_type, ...@@ -449,7 +451,6 @@ int Zygote::ForkWithRealPid(const std::string& process_type,
} }
} }
// In the child process.
write_pipe.reset(); write_pipe.reset();
// Ping the PID oracle socket so the browser can find our PID. // Ping the PID oracle socket so the browser can find our PID.
...@@ -476,32 +477,34 @@ int Zygote::ForkWithRealPid(const std::string& process_type, ...@@ -476,32 +477,34 @@ int Zygote::ForkWithRealPid(const std::string& process_type,
} }
// In the parent process. // In the parent process.
if (pid < 0) {
// Fork failed.
return -1;
}
read_pipe.reset(); read_pipe.reset();
pid_oracle.reset(); pid_oracle.reset();
// Always receive a real PID from the zygote host, though it might // Always receive a real PID from the zygote host, though it might
// be invalid (see below). // be invalid (see below).
base::ProcessId real_pid; base::ProcessId real_pid = -1;
{ {
std::vector<base::ScopedFD> recv_fds; std::vector<base::ScopedFD> recv_fds;
char buf[kZygoteMaxMessageLength]; char buf[kZygoteMaxMessageLength];
const ssize_t len = base::UnixDomainSocket::RecvMsg( const ssize_t len = base::UnixDomainSocket::RecvMsg(
kZygoteSocketPairFd, buf, sizeof(buf), &recv_fds); kZygoteSocketPairFd, buf, sizeof(buf), &recv_fds);
CHECK_GT(len, 0);
CHECK(recv_fds.empty());
base::Pickle pickle(buf, len); if (len > 0) {
base::PickleIterator iter(pickle); CHECK(recv_fds.empty());
int kind; base::Pickle pickle(buf, len);
CHECK(iter.ReadInt(&kind)); base::PickleIterator iter(pickle);
CHECK(kind == kZygoteCommandForkRealPID);
CHECK(iter.ReadInt(&real_pid));
}
// Fork failed. int kind;
if (pid < 0) { CHECK(iter.ReadInt(&kind));
return -1; CHECK(kind == kZygoteCommandForkRealPID);
CHECK(iter.ReadInt(&real_pid));
}
} }
// If we successfully forked a child, but it crashed without sending // If we successfully forked a child, but it crashed without sending
......
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