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 <sys/socket.h> | 7 #include <sys/socket.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // bad and it's easy. | 237 // bad and it's easy. |
238 | 238 |
239 static bool selinux; | 239 static bool selinux; |
240 static bool selinux_valid = false; | 240 static bool selinux_valid = false; |
241 | 241 |
242 if (!selinux_valid) { | 242 if (!selinux_valid) { |
243 const base::FilePath kSelinuxPath("/selinux"); | 243 const base::FilePath kSelinuxPath("/selinux"); |
244 base::FileEnumerator en(kSelinuxPath, false, base::FileEnumerator::FILES); | 244 base::FileEnumerator en(kSelinuxPath, false, base::FileEnumerator::FILES); |
245 bool has_selinux_files = !en.Next().empty(); | 245 bool has_selinux_files = !en.Next().empty(); |
246 | 246 |
247 selinux = access(kSelinuxPath.value().c_str(), X_OK) == 0 && | 247 selinux = |
248 has_selinux_files; | 248 has_selinux_files && access(kSelinuxPath.value().c_str(), X_OK) == 0; |
249 selinux_valid = true; | 249 selinux_valid = true; |
250 } | 250 } |
251 | 251 |
252 if (use_suid_sandbox_for_adj_oom_score_ && !selinux) { | 252 if (!use_suid_sandbox_for_adj_oom_score_) { |
253 // If heap profiling is running, these processes are not exiting, at least | |
254 // on ChromeOS. The easiest thing to do is not launch them when profiling. | |
255 // TODO(stevenjb): Investigate further and fix. | |
256 if (base::allocator::IsHeapProfilerRunning()) | |
257 return; | |
258 | |
259 std::vector<std::string> adj_oom_score_cmdline; | |
260 adj_oom_score_cmdline.push_back(sandbox_binary_); | |
261 adj_oom_score_cmdline.push_back(sandbox::kAdjustOOMScoreSwitch); | |
262 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); | |
263 adj_oom_score_cmdline.push_back(base::IntToString(score)); | |
264 | |
265 base::Process sandbox_helper_process; | |
266 base::LaunchOptions options; | |
267 | |
268 // sandbox_helper_process is a setuid binary. | |
269 options.allow_new_privs = true; | |
270 | |
271 sandbox_helper_process = | |
272 base::LaunchProcess(adj_oom_score_cmdline, options); | |
273 if (sandbox_helper_process.IsValid()) | |
274 base::EnsureProcessGetsReaped(sandbox_helper_process.Pid()); | |
275 } else if (!use_suid_sandbox_for_adj_oom_score_) { | |
276 if (!base::AdjustOOMScore(pid, score)) | 253 if (!base::AdjustOOMScore(pid, score)) |
277 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; | 254 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; |
| 255 return; |
278 } | 256 } |
| 257 |
| 258 if (selinux) |
| 259 return; |
| 260 |
| 261 // If heap profiling is running, these processes are not exiting, at least |
| 262 // on ChromeOS. The easiest thing to do is not launch them when profiling. |
| 263 // TODO(stevenjb): Investigate further and fix. |
| 264 if (base::allocator::IsHeapProfilerRunning()) |
| 265 return; |
| 266 |
| 267 std::vector<std::string> adj_oom_score_cmdline; |
| 268 adj_oom_score_cmdline.push_back(sandbox_binary_); |
| 269 adj_oom_score_cmdline.push_back(sandbox::kAdjustOOMScoreSwitch); |
| 270 adj_oom_score_cmdline.push_back(base::Int64ToString(pid)); |
| 271 adj_oom_score_cmdline.push_back(base::IntToString(score)); |
| 272 |
| 273 // sandbox_helper_process is a setuid binary. |
| 274 base::LaunchOptions options; |
| 275 options.allow_new_privs = true; |
| 276 |
| 277 base::Process sandbox_helper_process = |
| 278 base::LaunchProcess(adj_oom_score_cmdline, options); |
| 279 if (sandbox_helper_process.IsValid()) |
| 280 base::EnsureProcessGetsReaped(sandbox_helper_process.Pid()); |
279 } | 281 } |
280 #endif | 282 #endif |
281 | 283 |
282 } // namespace content | 284 } // namespace content |
OLD | NEW |