| 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(0); |
| 124 } |
| 125 else |
| 126 _exit(0); |
| 114 return false; | 127 return false; |
| 115 } | 128 } |
| 116 | 129 |
| 117 if (len == -1) { | 130 if (len == -1) { |
| 118 PLOG(ERROR) << "Error reading message from browser"; | 131 PLOG(ERROR) << "Error reading message from browser"; |
| 119 return false; | 132 return false; |
| 120 } | 133 } |
| 121 | 134 |
| 122 Pickle pickle(buf, len); | 135 Pickle pickle(buf, len); |
| 123 PickleIterator iter(pickle); | 136 PickleIterator iter(pickle); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 LOG(WARNING) << "Error parsing GetTerminationStatus request " | 202 LOG(WARNING) << "Error parsing GetTerminationStatus request " |
| 190 << "from browser"; | 203 << "from browser"; |
| 191 return; | 204 return; |
| 192 } | 205 } |
| 193 | 206 |
| 194 base::TerminationStatus status; | 207 base::TerminationStatus status; |
| 195 int exit_code; | 208 int exit_code; |
| 196 if (UsingSUIDSandbox()) | 209 if (UsingSUIDSandbox()) |
| 197 child = real_pids_to_sandbox_pids[child]; | 210 child = real_pids_to_sandbox_pids[child]; |
| 198 if (child) { | 211 if (child) { |
| 199 if (known_dead) { | 212 if (known_dead && |
| 213 !CommandLine::ForCurrentProcess()-> |
| 214 HasSwitch(switches::kChildCleanExit)) { |
| 200 // If we know that the process is already dead and the kernel is cleaning | 215 // If we know that the process is already dead and the kernel is cleaning |
| 201 // it up, we do want to wait until it becomes a zombie and not risk | 216 // it up, we do want to wait until it becomes a zombie and not risk |
| 202 // returning eroneously that it is still running. However, we do not | 217 // returning eroneously that it is still running. However, we do not |
| 203 // want to risk a bug where we're told a process is dead when it's not. | 218 // want to risk a bug where we're told a process is dead when it's not. |
| 204 // By sending SIGKILL, we make sure that WaitForTerminationStatus will | 219 // By sending SIGKILL, we make sure that WaitForTerminationStatus will |
| 205 // return quickly even in this case. | 220 // return quickly even in this case. |
| 206 if (kill(child, SIGKILL)) { | 221 if (kill(child, SIGKILL)) { |
| 207 PLOG(ERROR) << "kill (" << child << ")"; | 222 PLOG(ERROR) << "kill (" << child << ")"; |
| 208 } | 223 } |
| 209 status = base::WaitForTerminationStatus(child, &exit_code); | 224 status = base::WaitForTerminationStatus(child, &exit_code); |
| (...skipping 265 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 |