OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/zygote/zygote_linux.h" | 5 #include "content/zygote/zygote_linux.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 70 } |
71 | 71 |
72 // Kill the child process in case it's not already dead, so we can safely | 72 // Kill the child process in case it's not already dead, so we can safely |
73 // perform a blocking wait. | 73 // perform a blocking wait. |
74 PCHECK(0 == kill(pid, SIGKILL)); | 74 PCHECK(0 == kill(pid, SIGKILL)); |
75 PCHECK(pid == HANDLE_EINTR(waitpid(pid, NULL, 0))); | 75 PCHECK(pid == HANDLE_EINTR(waitpid(pid, NULL, 0))); |
76 } | 76 } |
77 | 77 |
78 } // namespace | 78 } // namespace |
79 | 79 |
80 Zygote::Zygote(int sandbox_flags, ScopedVector<ZygoteForkDelegate> helpers) | 80 Zygote::Zygote(int sandbox_flags, ScopedVector<ZygoteForkDelegate> helpers, |
81 const std::vector<base::ProcessHandle>& extra_children, | |
82 const std::vector<int>& extra_fds) | |
81 : sandbox_flags_(sandbox_flags), | 83 : sandbox_flags_(sandbox_flags), |
82 helpers_(helpers.Pass()), | 84 helpers_(helpers.Pass()), |
83 initial_uma_index_(0) { | 85 initial_uma_index_(0), |
84 } | 86 extra_children_(extra_children), |
87 extra_fds_(extra_fds) {} | |
85 | 88 |
86 Zygote::~Zygote() { | 89 Zygote::~Zygote() { |
87 } | 90 } |
88 | 91 |
89 bool Zygote::ProcessRequests() { | 92 bool Zygote::ProcessRequests() { |
90 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the | 93 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the |
91 // browser on it. | 94 // browser on it. |
92 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel. | 95 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel. |
93 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC | 96 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC |
94 | 97 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 bool Zygote::UsingSUIDSandbox() const { | 142 bool Zygote::UsingSUIDSandbox() const { |
140 return sandbox_flags_ & kSandboxLinuxSUID; | 143 return sandbox_flags_ & kSandboxLinuxSUID; |
141 } | 144 } |
142 | 145 |
143 bool Zygote::HandleRequestFromBrowser(int fd) { | 146 bool Zygote::HandleRequestFromBrowser(int fd) { |
144 ScopedVector<base::ScopedFD> fds; | 147 ScopedVector<base::ScopedFD> fds; |
145 char buf[kZygoteMaxMessageLength]; | 148 char buf[kZygoteMaxMessageLength]; |
146 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); | 149 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); |
147 | 150 |
148 if (len == 0 || (len == -1 && errno == ECONNRESET)) { | 151 if (len == 0 || (len == -1 && errno == ECONNRESET)) { |
149 // EOF from the browser. We should die. | 152 // EOF from the browser. We should die. |
earthdok
2014/05/27 12:50:12
Note to self: call __asan_cov_dump() to dump cover
| |
153 for (std::vector<int>::iterator it = extra_fds_.begin(); | |
jln (very slow on Chromium)
2014/05/27 23:15:00
Would you mind adding a TODO(earthdok) to replace
earthdok
2014/05/28 16:44:51
I was planning to add the call as part of this CL,
jln (very slow on Chromium)
2014/05/29 23:29:19
Yeah, it would be nice to get rid of extra_fds_.
| |
154 it < extra_fds_.end(); it++) | |
jln (very slow on Chromium)
2014/05/27 23:15:00
Style: always use {} for multi-line if/for
jln (very slow on Chromium)
2014/05/27 23:15:00
Nit: ++it is more idiomatic than it++ as it never
earthdok
2014/05/28 16:44:51
Done.
earthdok
2014/05/28 16:44:51
Done.
| |
155 PCHECK(0 == IGNORE_EINTR(close(*it))); | |
156 for (std::vector<base::ProcessHandle>::iterator it = | |
157 extra_children_.begin(); | |
158 it < extra_children_.end(); it++) | |
jln (very slow on Chromium)
2014/05/27 23:15:00
Style: {}
jln (very slow on Chromium)
2014/05/27 23:15:00
Nit: ++it
earthdok
2014/05/28 16:44:51
Done.
earthdok
2014/05/28 16:44:51
Done.
| |
159 PCHECK(*it == HANDLE_EINTR(waitpid(*it, NULL, 0))); | |
jln (very slow on Chromium)
2014/05/27 23:15:00
I'm a little scared of the implicit requirement th
earthdok
2014/05/28 16:44:51
Like I said, I'm willing to implement the watchdog
jln (very slow on Chromium)
2014/05/29 23:29:19
I wonder if we could simply use base::Watchdog for
| |
150 _exit(0); | 160 _exit(0); |
151 return false; | 161 return false; |
152 } | 162 } |
153 | 163 |
154 if (len == -1) { | 164 if (len == -1) { |
155 PLOG(ERROR) << "Error reading message from browser"; | 165 PLOG(ERROR) << "Error reading message from browser"; |
156 return false; | 166 return false; |
157 } | 167 } |
158 | 168 |
159 Pickle pickle(buf, len); | 169 Pickle pickle(buf, len); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 PickleIterator iter) { | 571 PickleIterator iter) { |
562 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != | 572 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != |
563 sizeof(sandbox_flags_)) { | 573 sizeof(sandbox_flags_)) { |
564 PLOG(ERROR) << "write"; | 574 PLOG(ERROR) << "write"; |
565 } | 575 } |
566 | 576 |
567 return false; | 577 return false; |
568 } | 578 } |
569 | 579 |
570 } // namespace content | 580 } // namespace content |
OLD | NEW |