| 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 "base/process_util.h" | 5 #include "base/process_util.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <malloc.h> | 8 #include <malloc.h> |
| 9 #include <sys/time.h> | 9 #include <sys/time.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 #else | 749 #else |
| 750 // Set the new-out of memory handler. | 750 // Set the new-out of memory handler. |
| 751 std::set_new_handler(&OnNoMemory); | 751 std::set_new_handler(&OnNoMemory); |
| 752 // If we're using glibc's allocator, the above functions will override | 752 // If we're using glibc's allocator, the above functions will override |
| 753 // malloc and friends and make them die on out of memory. | 753 // malloc and friends and make them die on out of memory. |
| 754 #endif | 754 #endif |
| 755 } | 755 } |
| 756 | 756 |
| 757 // NOTE: This is not the only version of this function in the source: | 757 // NOTE: This is not the only version of this function in the source: |
| 758 // the setuid sandbox (in process_util_linux.c, in the sandbox source) | 758 // the setuid sandbox (in process_util_linux.c, in the sandbox source) |
| 759 // also has it's own C version. | 759 // also has its own C version. |
| 760 bool AdjustOOMScore(ProcessId process, int score) { | 760 bool AdjustOOMScore(ProcessId process, int score) { |
| 761 if (score < 0 || score > kMaxOomScore) | 761 if (score < 0 || score > kMaxOomScore) |
| 762 return false; | 762 return false; |
| 763 | 763 |
| 764 FilePath oom_path(GetProcPidDir(process)); | 764 FilePath oom_path(GetProcPidDir(process)); |
| 765 | 765 |
| 766 // Attempt to write the newer oom_score_adj file first. | 766 // Attempt to write the newer oom_score_adj file first. |
| 767 FilePath oom_file = oom_path.AppendASCII("oom_score_adj"); | 767 FilePath oom_file = oom_path.AppendASCII("oom_score_adj"); |
| 768 if (file_util::PathExists(oom_file)) { | 768 if (file_util::PathExists(oom_file)) { |
| 769 std::string score_str = base::IntToString(score); | 769 std::string score_str = base::IntToString(score); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 789 int score_len = static_cast<int>(score_str.length()); | 789 int score_len = static_cast<int>(score_str.length()); |
| 790 return (score_len == file_util::WriteFile(oom_file, | 790 return (score_len == file_util::WriteFile(oom_file, |
| 791 score_str.c_str(), | 791 score_str.c_str(), |
| 792 score_len)); | 792 score_len)); |
| 793 } | 793 } |
| 794 | 794 |
| 795 return false; | 795 return false; |
| 796 } | 796 } |
| 797 | 797 |
| 798 } // namespace base | 798 } // namespace base |
| OLD | NEW |