| 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 "base/allocator/allocator_extension.h" |
| 7 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 8 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
| 9 #include "base/process/memory.h" | 10 #include "base/process/memory.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
| 12 #include "sandbox/linux/suid/common/sandbox.h" | 13 #include "sandbox/linux/suid/common/sandbox.h" |
| 13 | 14 |
| 14 #if defined(USE_TCMALLOC) | |
| 15 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | |
| 16 #endif | |
| 17 | |
| 18 namespace content { | 15 namespace content { |
| 19 | 16 |
| 20 // static | 17 // static |
| 21 ZygoteHost* ZygoteHost::GetInstance() { | 18 ZygoteHost* ZygoteHost::GetInstance() { |
| 22 return ZygoteHostImpl::GetInstance(); | 19 return ZygoteHostImpl::GetInstance(); |
| 23 } | 20 } |
| 24 | 21 |
| 25 ZygoteHostImpl::ZygoteHostImpl() | 22 ZygoteHostImpl::ZygoteHostImpl() |
| 26 : use_suid_sandbox_for_adj_oom_score_(false), | 23 : use_suid_sandbox_for_adj_oom_score_(false), |
| 27 sandbox_binary_(), | 24 sandbox_binary_(), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const base::FilePath kSelinuxPath("/selinux"); | 94 const base::FilePath kSelinuxPath("/selinux"); |
| 98 base::FileEnumerator en(kSelinuxPath, false, base::FileEnumerator::FILES); | 95 base::FileEnumerator en(kSelinuxPath, false, base::FileEnumerator::FILES); |
| 99 bool has_selinux_files = !en.Next().empty(); | 96 bool has_selinux_files = !en.Next().empty(); |
| 100 | 97 |
| 101 selinux = access(kSelinuxPath.value().c_str(), X_OK) == 0 && | 98 selinux = access(kSelinuxPath.value().c_str(), X_OK) == 0 && |
| 102 has_selinux_files; | 99 has_selinux_files; |
| 103 selinux_valid = true; | 100 selinux_valid = true; |
| 104 } | 101 } |
| 105 | 102 |
| 106 if (use_suid_sandbox_for_adj_oom_score_ && !selinux) { | 103 if (use_suid_sandbox_for_adj_oom_score_ && !selinux) { |
| 107 #if defined(USE_TCMALLOC) | |
| 108 // If heap profiling is running, these processes are not exiting, at least | 104 // If heap profiling is running, these processes are not exiting, at least |
| 109 // on ChromeOS. The easiest thing to do is not launch them when profiling. | 105 // on ChromeOS. The easiest thing to do is not launch them when profiling. |
| 110 // TODO(stevenjb): Investigate further and fix. | 106 // TODO(stevenjb): Investigate further and fix. |
| 111 if (IsHeapProfilerRunning()) | 107 if (base::allocator::IsHeapProfilerRunning()) |
| 112 return; | 108 return; |
| 113 #endif | 109 |
| 114 std::vector<std::string> adj_oom_score_cmdline; | 110 std::vector<std::string> adj_oom_score_cmdline; |
| 115 adj_oom_score_cmdline.push_back(sandbox_binary_); | 111 adj_oom_score_cmdline.push_back(sandbox_binary_); |
| 116 adj_oom_score_cmdline.push_back(sandbox::kAdjustOOMScoreSwitch); | 112 adj_oom_score_cmdline.push_back(sandbox::kAdjustOOMScoreSwitch); |
| 117 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); | 113 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); |
| 118 adj_oom_score_cmdline.push_back(base::IntToString(score)); | 114 adj_oom_score_cmdline.push_back(base::IntToString(score)); |
| 119 | 115 |
| 120 base::Process sandbox_helper_process; | 116 base::Process sandbox_helper_process; |
| 121 base::LaunchOptions options; | 117 base::LaunchOptions options; |
| 122 | 118 |
| 123 // sandbox_helper_process is a setuid binary. | 119 // sandbox_helper_process is a setuid binary. |
| 124 options.allow_new_privs = true; | 120 options.allow_new_privs = true; |
| 125 | 121 |
| 126 sandbox_helper_process = | 122 sandbox_helper_process = |
| 127 base::LaunchProcess(adj_oom_score_cmdline, options); | 123 base::LaunchProcess(adj_oom_score_cmdline, options); |
| 128 if (sandbox_helper_process.IsValid()) | 124 if (sandbox_helper_process.IsValid()) |
| 129 base::EnsureProcessGetsReaped(sandbox_helper_process.Pid()); | 125 base::EnsureProcessGetsReaped(sandbox_helper_process.Pid()); |
| 130 } else if (!use_suid_sandbox_for_adj_oom_score_) { | 126 } else if (!use_suid_sandbox_for_adj_oom_score_) { |
| 131 if (!base::AdjustOOMScore(pid, score)) | 127 if (!base::AdjustOOMScore(pid, score)) |
| 132 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; | 128 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; |
| 133 } | 129 } |
| 134 } | 130 } |
| 135 #endif | 131 #endif |
| 136 | 132 |
| 137 } // namespace content | 133 } // namespace content |
| OLD | NEW |