| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 uma_boundary_value, | 299 uma_boundary_value, |
| 300 uma_boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag); | 300 uma_boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag); |
| 301 } | 301 } |
| 302 uma_histogram->Add(uma_sample); | 302 uma_histogram->Add(uma_sample); |
| 303 } | 303 } |
| 304 | 304 |
| 305 if (pid <= 0) | 305 if (pid <= 0) |
| 306 return base::kNullProcessHandle; | 306 return base::kNullProcessHandle; |
| 307 } | 307 } |
| 308 | 308 |
| 309 #if !defined(OS_OPENBSD) |
| 309 // This is just a starting score for a renderer or extension (the | 310 // This is just a starting score for a renderer or extension (the |
| 310 // only types of processes that will be started this way). It will | 311 // only types of processes that will be started this way). It will |
| 311 // get adjusted as time goes on. (This is the same value as | 312 // get adjusted as time goes on. (This is the same value as |
| 312 // chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but | 313 // chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but |
| 313 // that's not something we can include here.) | 314 // that's not something we can include here.) |
| 314 const int kLowestRendererOomScore = 300; | 315 const int kLowestRendererOomScore = 300; |
| 315 AdjustRendererOOMScore(pid, kLowestRendererOomScore); | 316 AdjustRendererOOMScore(pid, kLowestRendererOomScore); |
| 317 #endif |
| 316 | 318 |
| 317 return pid; | 319 return pid; |
| 318 } | 320 } |
| 319 | 321 |
| 322 #if !defined(OS_OPENBSD) |
| 320 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { | 323 void ZygoteHost::AdjustRendererOOMScore(base::ProcessHandle pid, int score) { |
| 321 // 1) You can't change the oom_score_adj of a non-dumpable process | 324 // 1) You can't change the oom_score_adj of a non-dumpable process |
| 322 // (EPERM) unless you're root. Because of this, we can't set the | 325 // (EPERM) unless you're root. Because of this, we can't set the |
| 323 // oom_adj from the browser process. | 326 // oom_adj from the browser process. |
| 324 // | 327 // |
| 325 // 2) We can't set the oom_score_adj before entering the sandbox | 328 // 2) We can't set the oom_score_adj before entering the sandbox |
| 326 // because the zygote is in the sandbox and the zygote is as | 329 // because the zygote is in the sandbox and the zygote is as |
| 327 // critical as the browser process. Its oom_adj value shouldn't | 330 // critical as the browser process. Its oom_adj value shouldn't |
| 328 // be changed. | 331 // be changed. |
| 329 // | 332 // |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 base::ProcessHandle sandbox_helper_process; | 379 base::ProcessHandle sandbox_helper_process; |
| 377 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(), | 380 if (base::LaunchProcess(adj_oom_score_cmdline, base::LaunchOptions(), |
| 378 &sandbox_helper_process)) { | 381 &sandbox_helper_process)) { |
| 379 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); | 382 ProcessWatcher::EnsureProcessGetsReaped(sandbox_helper_process); |
| 380 } | 383 } |
| 381 } else if (!using_suid_sandbox_) { | 384 } else if (!using_suid_sandbox_) { |
| 382 if (!base::AdjustOOMScore(pid, score)) | 385 if (!base::AdjustOOMScore(pid, score)) |
| 383 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; | 386 PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid; |
| 384 } | 387 } |
| 385 } | 388 } |
| 389 #endif |
| 386 | 390 |
| 387 void ZygoteHost::EnsureProcessTerminated(pid_t process) { | 391 void ZygoteHost::EnsureProcessTerminated(pid_t process) { |
| 388 DCHECK(init_); | 392 DCHECK(init_); |
| 389 Pickle pickle; | 393 Pickle pickle; |
| 390 | 394 |
| 391 pickle.WriteInt(kCmdReap); | 395 pickle.WriteInt(kCmdReap); |
| 392 pickle.WriteInt(process); | 396 pickle.WriteInt(process); |
| 393 | 397 |
| 394 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) | 398 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) |
| 395 PLOG(ERROR) << "write"; | 399 PLOG(ERROR) << "write"; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { | 437 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
| 434 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; | 438 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
| 435 return base::TERMINATION_STATUS_NORMAL_TERMINATION; | 439 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
| 436 } | 440 } |
| 437 | 441 |
| 438 if (exit_code) | 442 if (exit_code) |
| 439 *exit_code = tmp_exit_code; | 443 *exit_code = tmp_exit_code; |
| 440 | 444 |
| 441 return static_cast<base::TerminationStatus>(status); | 445 return static_cast<base::TerminationStatus>(status); |
| 442 } | 446 } |
| OLD | NEW |