| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_linux.h" | 5 #include "content/browser/zygote_host_linux.h" |
| 6 | 6 |
| 7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 int dummy_fd = -1; | 145 int dummy_fd = -1; |
| 146 if (using_suid_sandbox_) { | 146 if (using_suid_sandbox_) { |
| 147 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0); | 147 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 148 CHECK(dummy_fd >= 0); | 148 CHECK(dummy_fd >= 0); |
| 149 fds_to_map.push_back(std::make_pair(dummy_fd, 7)); | 149 fds_to_map.push_back(std::make_pair(dummy_fd, 7)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 base::ProcessHandle process = -1; | 152 base::ProcessHandle process = -1; |
| 153 base::LaunchOptions options; | 153 base::LaunchOptions options; |
| 154 options.process_handle = &process; | |
| 155 options.fds_to_remap = &fds_to_map; | 154 options.fds_to_remap = &fds_to_map; |
| 156 base::LaunchProcess(cmd_line.argv(), options); | 155 base::LaunchProcess(cmd_line.argv(), options, &process); |
| 157 CHECK(process != -1) << "Failed to launch zygote process"; | 156 CHECK(process != -1) << "Failed to launch zygote process"; |
| 158 | 157 |
| 159 if (using_suid_sandbox_) { | 158 if (using_suid_sandbox_) { |
| 160 // In the SUID sandbox, the real zygote is forked from the sandbox. | 159 // In the SUID sandbox, the real zygote is forked from the sandbox. |
| 161 // We need to look for it. | 160 // We need to look for it. |
| 162 // But first, wait for the zygote to tell us it's running. | 161 // But first, wait for the zygote to tell us it's running. |
| 163 // The sending code is in chrome/browser/zygote_main_linux.cc. | 162 // The sending code is in chrome/browser/zygote_main_linux.cc. |
| 164 std::vector<int> fds_vec; | 163 std::vector<int> fds_vec; |
| 165 const int kExpectedLength = sizeof(kZygoteMagic); | 164 const int kExpectedLength = sizeof(kZygoteMagic); |
| 166 char buf[kExpectedLength]; | 165 char buf[kExpectedLength]; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 297 } |
| 299 | 298 |
| 300 if (using_suid_sandbox_ && !selinux) { | 299 if (using_suid_sandbox_ && !selinux) { |
| 301 std::vector<std::string> adj_oom_score_cmdline; | 300 std::vector<std::string> adj_oom_score_cmdline; |
| 302 adj_oom_score_cmdline.push_back(sandbox_binary_); | 301 adj_oom_score_cmdline.push_back(sandbox_binary_); |
| 303 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch); | 302 adj_oom_score_cmdline.push_back(base::kAdjustOOMScoreSwitch); |
| 304 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); | 303 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); |
| 305 adj_oom_score_cmdline.push_back(base::IntToString(score)); | 304 adj_oom_score_cmdline.push_back(base::IntToString(score)); |
| 306 | 305 |
| 307 base::ProcessHandle sandbox_helper_process; | 306 base::ProcessHandle sandbox_helper_process; |
| 308 base::LaunchOptions options; | 307 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(), |
| 309 options.process_handle = &sandbox_helper_process; | 308 &sandbox_helper_process)) { |
| 310 if (base::LaunchProcess(adj_oom_score_cmdline, options)) | |
| 311 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); | 309 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); |
| 310 } |
| 312 } else if (!using_suid_sandbox_) { | 311 } else if (!using_suid_sandbox_) { |
| 313 if (!base::AdjustOOMScore(pid, score)) | 312 if (!base::AdjustOOMScore(pid, score)) |
| 314 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; | 313 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; |
| 315 } | 314 } |
| 316 } | 315 } |
| 317 | 316 |
| 318 void ZygoteHost::EnsureProcessTerminated(pid_t process) { | 317 void ZygoteHost::EnsureProcessTerminated(pid_t process) { |
| 319 DCHECK(init_); | 318 DCHECK(init_); |
| 320 Pickle pickle; | 319 Pickle pickle; |
| 321 | 320 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { | 363 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
| 365 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; | 364 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
| 366 return base::TERMINATION_STATUS_NORMAL_TERMINATION; | 365 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
| 367 } | 366 } |
| 368 | 367 |
| 369 if (exit_code) | 368 if (exit_code) |
| 370 *exit_code = tmp_exit_code; | 369 *exit_code = tmp_exit_code; |
| 371 | 370 |
| 372 return static_cast<base::TerminationStatus>(status); | 371 return static_cast<base::TerminationStatus>(status); |
| 373 } | 372 } |
| OLD | NEW |