Chromium Code Reviews| 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 // Wait for all children to exit first. | |
|
Markus (顧孟勤)
2013/07/18 23:26:47
This comment is super confusing. This might very w
asharif1
2013/07/19 03:01:32
I will try to clarify this comment in the next pat
| |
| 118 pthread_exit(NULL); | |
|
jln (very slow on Chromium)
2013/07/18 23:26:05
What are you trying to do here ?
You're exiting t
asharif1
2013/07/19 03:01:32
Although this process seems single-threaded, close
| |
| 119 else | |
| 120 _exit(0); | |
| 114 return false; | 121 return false; |
| 115 } | 122 } |
| 116 | 123 |
| 117 if (len == -1) { | 124 if (len == -1) { |
| 118 PLOG(ERROR) << "Error reading message from browser"; | 125 PLOG(ERROR) << "Error reading message from browser"; |
| 119 return false; | 126 return false; |
| 120 } | 127 } |
| 121 | 128 |
| 122 Pickle pickle(buf, len); | 129 Pickle pickle(buf, len); |
| 123 PickleIterator iter(pickle); | 130 PickleIterator iter(pickle); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 175 |
| 169 if (UsingSUIDSandbox()) { | 176 if (UsingSUIDSandbox()) { |
| 170 actual_child = real_pids_to_sandbox_pids[child]; | 177 actual_child = real_pids_to_sandbox_pids[child]; |
| 171 if (!actual_child) | 178 if (!actual_child) |
| 172 return; | 179 return; |
| 173 real_pids_to_sandbox_pids.erase(child); | 180 real_pids_to_sandbox_pids.erase(child); |
| 174 } else { | 181 } else { |
| 175 actual_child = child; | 182 actual_child = child; |
| 176 } | 183 } |
| 177 | 184 |
| 178 base::EnsureProcessTerminated(actual_child); | 185 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChildCleanExit)) |
| 186 base::EnsureProcessGetsReaped(actual_child); | |
| 187 else | |
| 188 base::EnsureProcessTerminated(actual_child); | |
| 179 } | 189 } |
| 180 | 190 |
| 181 void Zygote::HandleGetTerminationStatus(int fd, | 191 void Zygote::HandleGetTerminationStatus(int fd, |
| 182 const Pickle& pickle, | 192 const Pickle& pickle, |
| 183 PickleIterator iter) { | 193 PickleIterator iter) { |
| 184 bool known_dead; | 194 bool known_dead; |
| 185 base::ProcessHandle child; | 195 base::ProcessHandle child; |
| 186 | 196 |
| 187 if (!pickle.ReadBool(&iter, &known_dead) || | 197 if (!pickle.ReadBool(&iter, &known_dead) || |
| 188 !pickle.ReadInt(&iter, &child)) { | 198 !pickle.ReadInt(&iter, &child)) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 PickleIterator iter) { | 485 PickleIterator iter) { |
| 476 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != | 486 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != |
| 477 sizeof(sandbox_flags_)) { | 487 sizeof(sandbox_flags_)) { |
| 478 PLOG(ERROR) << "write"; | 488 PLOG(ERROR) << "write"; |
| 479 } | 489 } |
| 480 | 490 |
| 481 return false; | 491 return false; |
| 482 } | 492 } |
| 483 | 493 |
| 484 } // namespace content | 494 } // namespace content |
| OLD | NEW |