| 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> |
| 11 | 11 |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/eintr_wrapper.h" | 14 #include "base/eintr_wrapper.h" |
| 15 #include "base/environment.h" | 15 #include "base/environment.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/linux_util.h" | 17 #include "base/linux_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 22 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
| 24 #include "base/string_number_conversions.h" | 24 #include "base/string_number_conversions.h" |
| 25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 26 #include "base/time.h" | 26 #include "base/time.h" |
| 27 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
| 28 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 28 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| 29 #include "content/common/process_watcher.h" | |
| 30 #include "content/common/unix_domain_socket_posix.h" | 29 #include "content/common/unix_domain_socket_posix.h" |
| 31 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
| 32 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 33 #include "content/public/common/result_codes.h" | 32 #include "content/public/common/result_codes.h" |
| 34 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" | 33 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" |
| 35 | 34 |
| 36 #if defined(USE_TCMALLOC) | 35 #if defined(USE_TCMALLOC) |
| 37 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" | 36 #include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" |
| 38 #endif | 37 #endif |
| 39 | 38 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 CommandLine get_inode_cmd(get_inode_cmdline); | 195 CommandLine get_inode_cmd(get_inode_cmdline); |
| 197 if (base::GetAppOutput(get_inode_cmd, &inode_output)) { | 196 if (base::GetAppOutput(get_inode_cmd, &inode_output)) { |
| 198 base::StringToInt(inode_output, &pid_); | 197 base::StringToInt(inode_output, &pid_); |
| 199 } | 198 } |
| 200 } | 199 } |
| 201 CHECK(pid_ > 0) << "Did not find zygote process (using sandbox binary " | 200 CHECK(pid_ > 0) << "Did not find zygote process (using sandbox binary " |
| 202 << sandbox_binary_ << ")"; | 201 << sandbox_binary_ << ")"; |
| 203 | 202 |
| 204 if (process != pid_) { | 203 if (process != pid_) { |
| 205 // Reap the sandbox. | 204 // Reap the sandbox. |
| 206 ProcessWatcher::EnsureProcessGetsReaped(process); | 205 base::EnsureProcessGetsReaped(process); |
| 207 } | 206 } |
| 208 } else { | 207 } else { |
| 209 // Not using the SUID sandbox. | 208 // Not using the SUID sandbox. |
| 210 pid_ = process; | 209 pid_ = process; |
| 211 } | 210 } |
| 212 | 211 |
| 213 close(fds[1]); | 212 close(fds[1]); |
| 214 control_fd_ = fds[0]; | 213 control_fd_ = fds[0]; |
| 215 | 214 |
| 216 Pickle pickle; | 215 Pickle pickle; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 371 |
| 373 std::vector<std::string> adj_oom_score_cmdline; | 372 std::vector<std::string> adj_oom_score_cmdline; |
| 374 adj_oom_score_cmdline.push_back(sandbox_binary_); | 373 adj_oom_score_cmdline.push_back(sandbox_binary_); |
| 375 adj_oom_score_cmdline.push_back(kAdjustOOMScoreSwitch); | 374 adj_oom_score_cmdline.push_back(kAdjustOOMScoreSwitch); |
| 376 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); | 375 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); |
| 377 adj_oom_score_cmdline.push_back(base::IntToString(score)); | 376 adj_oom_score_cmdline.push_back(base::IntToString(score)); |
| 378 | 377 |
| 379 base::ProcessHandle sandbox_helper_process; | 378 base::ProcessHandle sandbox_helper_process; |
| 380 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(), | 379 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(), |
| 381 &sandbox_helper_process)) { | 380 &sandbox_helper_process)) { |
| 382 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); | 381 base::EnsureProcessGetsReaped(sandbox_helper_process); |
| 383 } | 382 } |
| 384 } else if (!using_suid_sandbox_) { | 383 } else if (!using_suid_sandbox_) { |
| 385 if (!base::AdjustOOMScore(pid, score)) | 384 if (!base::AdjustOOMScore(pid, score)) |
| 386 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; | 385 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; |
| 387 } | 386 } |
| 388 } | 387 } |
| 389 #endif | 388 #endif |
| 390 | 389 |
| 391 void ZygoteHost::EnsureProcessTerminated(pid_t process) { | 390 void ZygoteHost::EnsureProcessTerminated(pid_t process) { |
| 392 DCHECK(init_); | 391 DCHECK(init_); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { | 436 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
| 438 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; | 437 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
| 439 return base::TERMINATION_STATUS_NORMAL_TERMINATION; | 438 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
| 440 } | 439 } |
| 441 | 440 |
| 442 if (exit_code) | 441 if (exit_code) |
| 443 *exit_code = tmp_exit_code; | 442 *exit_code = tmp_exit_code; |
| 444 | 443 |
| 445 return static_cast<base::TerminationStatus>(status); | 444 return static_cast<base::TerminationStatus>(status); |
| 446 } | 445 } |
| OLD | NEW |