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 <pthread.h> |
8 #include <string.h> | 9 #include <string.h> |
9 #include <sys/socket.h> | 10 #include <sys/socket.h> |
10 #include <sys/types.h> | 11 #include <sys/types.h> |
11 #include <sys/wait.h> | 12 #include <sys/wait.h> |
12 | 13 |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/linux_util.h" | 17 #include "base/linux_util.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/pickle.h" | 19 #include "base/pickle.h" |
19 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
20 #include "base/posix/global_descriptors.h" | 21 #include "base/posix/global_descriptors.h" |
21 #include "base/posix/unix_domain_socket_linux.h" | 22 #include "base/posix/unix_domain_socket_linux.h" |
22 #include "base/process_util.h" | 23 #include "base/process_util.h" |
23 #include "content/common/sandbox_linux.h" | 24 #include "content/common/sandbox_linux.h" |
24 #include "content/common/set_process_title.h" | 25 #include "content/common/set_process_title.h" |
25 #include "content/common/zygote_commands_linux.h" | 26 #include "content/common/zygote_commands_linux.h" |
26 #include "content/public/common/content_descriptors.h" | 27 #include "content/public/common/content_descriptors.h" |
| 28 #include "content/public/common/content_switches.h" |
27 #include "content/public/common/result_codes.h" | 29 #include "content/public/common/result_codes.h" |
28 #include "content/public/common/sandbox_linux.h" | 30 #include "content/public/common/sandbox_linux.h" |
29 #include "content/public/common/zygote_fork_delegate_linux.h" | 31 #include "content/public/common/zygote_fork_delegate_linux.h" |
30 #include "ipc/ipc_channel.h" | 32 #include "ipc/ipc_channel.h" |
31 #include "ipc/ipc_switches.h" | 33 #include "ipc/ipc_switches.h" |
32 | 34 |
33 // See http://code.google.com/p/chromium/wiki/LinuxZygote | 35 // See http://code.google.com/p/chromium/wiki/LinuxZygote |
34 | 36 |
35 namespace content { | 37 namespace content { |
36 | 38 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 return sandbox_flags_ & kSandboxLinuxSUID; | 105 return sandbox_flags_ & kSandboxLinuxSUID; |
104 } | 106 } |
105 | 107 |
106 bool Zygote::HandleRequestFromBrowser(int fd) { | 108 bool Zygote::HandleRequestFromBrowser(int fd) { |
107 std::vector<int> fds; | 109 std::vector<int> fds; |
108 char buf[kZygoteMaxMessageLength]; | 110 char buf[kZygoteMaxMessageLength]; |
109 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); | 111 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); |
110 | 112 |
111 if (len == 0 || (len == -1 && errno == ECONNRESET)) { | 113 if (len == 0 || (len == -1 && errno == ECONNRESET)) { |
112 // EOF from the browser. We should die. | 114 // EOF from the browser. We should die. |
113 _exit(0); | 115 if (CommandLine::ForCurrentProcess()-> |
| 116 HasSwitch(switches::kChildCleanExit)) |
| 117 // Zygote children are reaped in a separate detached thread (see the |
| 118 // implementation of EnsureProcessGetsReaped()). If we _exit() or exit() |
| 119 // here, the reaping wait may not have completed. For this reason, we |
| 120 // only terminate this thread (instead of terminating the whole process). |
| 121 // The zygote will then exit only when all children have exited and have |
| 122 // been reaped. |
| 123 pthread_exit(NULL); |
| 124 else |
| 125 _exit(0); |
114 return false; | 126 return false; |
115 } | 127 } |
116 | 128 |
117 if (len == -1) { | 129 if (len == -1) { |
118 PLOG(ERROR) << "Error reading message from browser"; | 130 PLOG(ERROR) << "Error reading message from browser"; |
119 return false; | 131 return false; |
120 } | 132 } |
121 | 133 |
122 Pickle pickle(buf, len); | 134 Pickle pickle(buf, len); |
123 PickleIterator iter(pickle); | 135 PickleIterator iter(pickle); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 180 |
169 if (UsingSUIDSandbox()) { | 181 if (UsingSUIDSandbox()) { |
170 actual_child = real_pids_to_sandbox_pids[child]; | 182 actual_child = real_pids_to_sandbox_pids[child]; |
171 if (!actual_child) | 183 if (!actual_child) |
172 return; | 184 return; |
173 real_pids_to_sandbox_pids.erase(child); | 185 real_pids_to_sandbox_pids.erase(child); |
174 } else { | 186 } else { |
175 actual_child = child; | 187 actual_child = child; |
176 } | 188 } |
177 | 189 |
178 base::EnsureProcessTerminated(actual_child); | 190 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChildCleanExit)) |
| 191 base::EnsureProcessGetsReaped(actual_child); |
| 192 else |
| 193 base::EnsureProcessTerminated(actual_child); |
179 } | 194 } |
180 | 195 |
181 void Zygote::HandleGetTerminationStatus(int fd, | 196 void Zygote::HandleGetTerminationStatus(int fd, |
182 const Pickle& pickle, | 197 const Pickle& pickle, |
183 PickleIterator iter) { | 198 PickleIterator iter) { |
184 bool known_dead; | 199 bool known_dead; |
185 base::ProcessHandle child; | 200 base::ProcessHandle child; |
186 | 201 |
187 if (!pickle.ReadBool(&iter, &known_dead) || | 202 if (!pickle.ReadBool(&iter, &known_dead) || |
188 !pickle.ReadInt(&iter, &child)) { | 203 !pickle.ReadInt(&iter, &child)) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 PickleIterator iter) { | 490 PickleIterator iter) { |
476 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != | 491 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != |
477 sizeof(sandbox_flags_)) { | 492 sizeof(sandbox_flags_)) { |
478 PLOG(ERROR) << "write"; | 493 PLOG(ERROR) << "write"; |
479 } | 494 } |
480 | 495 |
481 return false; | 496 return false; |
482 } | 497 } |
483 | 498 |
484 } // namespace content | 499 } // namespace content |
OLD | NEW |