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/browser/zygote_host/zygote_host_impl_linux.h" | 5 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 << "Received invalid process ID for zygote; kernel might be too old? " | 180 << "Received invalid process ID for zygote; kernel might be too old? " |
181 "See crbug.com/357670 or try using --" | 181 "See crbug.com/357670 or try using --" |
182 << switches::kDisableSetuidSandbox << " to workaround."; | 182 << switches::kDisableSetuidSandbox << " to workaround."; |
183 | 183 |
184 // Now receive the message that the zygote's ready to go, along with the | 184 // Now receive the message that the zygote's ready to go, along with the |
185 // main zygote process's ID. | 185 // main zygote process's ID. |
186 CHECK(ReceiveFixedMessage( | 186 CHECK(ReceiveFixedMessage( |
187 fds[0], kZygoteHelloMessage, sizeof(kZygoteHelloMessage), &pid_)); | 187 fds[0], kZygoteHelloMessage, sizeof(kZygoteHelloMessage), &pid_)); |
188 CHECK_GT(pid_, 1); | 188 CHECK_GT(pid_, 1); |
189 | 189 |
190 if (process.pid() != pid_) { | 190 if (process.Pid() != pid_) { |
191 // Reap the sandbox. | 191 // Reap the sandbox. |
192 base::EnsureProcessGetsReaped(process.pid()); | 192 base::EnsureProcessGetsReaped(process.Pid()); |
193 } | 193 } |
194 } else { | 194 } else { |
195 // Not using the SUID sandbox. | 195 // Not using the SUID sandbox. |
196 // Note that ~base::Process() will reset the internal value, but there's no | 196 // Note that ~base::Process() will reset the internal value, but there's no |
197 // real "handle" on POSIX so that is safe. | 197 // real "handle" on POSIX so that is safe. |
198 pid_ = process.pid(); | 198 pid_ = process.Pid(); |
199 } | 199 } |
200 | 200 |
201 close(fds[1]); | 201 close(fds[1]); |
202 control_fd_ = fds[0]; | 202 control_fd_ = fds[0]; |
203 | 203 |
204 Pickle pickle; | 204 Pickle pickle; |
205 pickle.WriteInt(kZygoteCommandGetSandboxStatus); | 205 pickle.WriteInt(kZygoteCommandGetSandboxStatus); |
206 if (!SendMessage(pickle, NULL)) | 206 if (!SendMessage(pickle, NULL)) |
207 LOG(FATAL) << "Cannot communicate with zygote"; | 207 LOG(FATAL) << "Cannot communicate with zygote"; |
208 // We don't wait for the reply. We'll read it in ReadReply. | 208 // We don't wait for the reply. We'll read it in ReadReply. |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 474 |
475 base::Process sandbox_helper_process; | 475 base::Process sandbox_helper_process; |
476 base::LaunchOptions options; | 476 base::LaunchOptions options; |
477 | 477 |
478 // sandbox_helper_process is a setuid binary. | 478 // sandbox_helper_process is a setuid binary. |
479 options.allow_new_privs = true; | 479 options.allow_new_privs = true; |
480 | 480 |
481 sandbox_helper_process = | 481 sandbox_helper_process = |
482 base::LaunchProcess(adj_oom_score_cmdline, options); | 482 base::LaunchProcess(adj_oom_score_cmdline, options); |
483 if (sandbox_helper_process.IsValid()) | 483 if (sandbox_helper_process.IsValid()) |
484 base::EnsureProcessGetsReaped(sandbox_helper_process.pid()); | 484 base::EnsureProcessGetsReaped(sandbox_helper_process.Pid()); |
485 } else if (!using_suid_sandbox_) { | 485 } else if (!using_suid_sandbox_) { |
486 if (!base::AdjustOOMScore(pid, score)) | 486 if (!base::AdjustOOMScore(pid, score)) |
487 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; | 487 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; |
488 } | 488 } |
489 } | 489 } |
490 #endif | 490 #endif |
491 | 491 |
492 void ZygoteHostImpl::EnsureProcessTerminated(pid_t process) { | 492 void ZygoteHostImpl::EnsureProcessTerminated(pid_t process) { |
493 DCHECK(init_); | 493 DCHECK(init_); |
494 Pickle pickle; | 494 Pickle pickle; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 return pid_; | 553 return pid_; |
554 } | 554 } |
555 | 555 |
556 int ZygoteHostImpl::GetSandboxStatus() const { | 556 int ZygoteHostImpl::GetSandboxStatus() const { |
557 if (have_read_sandbox_status_word_) | 557 if (have_read_sandbox_status_word_) |
558 return sandbox_status_; | 558 return sandbox_status_; |
559 return 0; | 559 return 0; |
560 } | 560 } |
561 | 561 |
562 } // namespace content | 562 } // namespace content |
OLD | NEW |