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 // A mini-zygote specifically for Native Client. | 5 // A mini-zygote specifically for Native Client. |
6 | 6 |
7 #include "components/nacl/common/nacl_helper_linux.h" | 7 #include "components/nacl/common/nacl_helper_linux.h" |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 LOG(ERROR) << "Could not read known_dead status"; | 157 LOG(ERROR) << "Could not read known_dead status"; |
158 return false; | 158 return false; |
159 } | 159 } |
160 // TODO(jln): With NaCl, known_dead seems to never be set to true (unless | 160 // TODO(jln): With NaCl, known_dead seems to never be set to true (unless |
161 // called from the Zygote's kZygoteCommandReap command). This means that we | 161 // called from the Zygote's kZygoteCommandReap command). This means that we |
162 // will sometimes detect the process as still running when it's not. Fix | 162 // will sometimes detect the process as still running when it's not. Fix |
163 // this! | 163 // this! |
164 | 164 |
165 int exit_code; | 165 int exit_code; |
166 base::TerminationStatus status; | 166 base::TerminationStatus status; |
167 // See the comment in the Zygote about known_dead. | 167 if (known_dead) |
168 if (known_dead) { | 168 status = base::GetKnownDeadTerminationStatus(child_to_wait, &exit_code); |
169 // Make sure to not perform a blocking wait on something that | 169 else |
170 // could still be alive. | |
171 if (kill(child_to_wait, SIGKILL)) { | |
172 PLOG(ERROR) << "kill (" << child_to_wait << ")"; | |
173 } | |
174 status = base::WaitForTerminationStatus(child_to_wait, &exit_code); | |
175 } else { | |
176 status = base::GetTerminationStatus(child_to_wait, &exit_code); | 170 status = base::GetTerminationStatus(child_to_wait, &exit_code); |
177 } | |
178 output_pickle->WriteInt(static_cast<int>(status)); | 171 output_pickle->WriteInt(static_cast<int>(status)); |
179 output_pickle->WriteInt(exit_code); | 172 output_pickle->WriteInt(exit_code); |
180 return true; | 173 return true; |
181 } | 174 } |
182 | 175 |
183 // This is a poor man's check on whether we are sandboxed. | 176 // This is a poor man's check on whether we are sandboxed. |
184 bool IsSandboxed() { | 177 bool IsSandboxed() { |
185 int proc_fd = open("/proc/self/exe", O_RDONLY); | 178 int proc_fd = open("/proc/self/exe", O_RDONLY); |
186 if (proc_fd >= 0) { | 179 if (proc_fd >= 0) { |
187 HANDLE_EINTR(close(proc_fd)); | 180 HANDLE_EINTR(close(proc_fd)); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // Now handle requests from the Zygote. | 378 // Now handle requests from the Zygote. |
386 while (true) { | 379 while (true) { |
387 bool request_handled = HandleZygoteRequest(kNaClZygoteDescriptor, | 380 bool request_handled = HandleZygoteRequest(kNaClZygoteDescriptor, |
388 system_info); | 381 system_info); |
389 // Do not turn this into a CHECK() without thinking about robustness | 382 // Do not turn this into a CHECK() without thinking about robustness |
390 // against malicious IPC requests. | 383 // against malicious IPC requests. |
391 DCHECK(request_handled); | 384 DCHECK(request_handled); |
392 } | 385 } |
393 NOTREACHED(); | 386 NOTREACHED(); |
394 } | 387 } |
OLD | NEW |