| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <ctype.h> | 7 #include <ctype.h> |
| 8 #include <dirent.h> | 8 #include <dirent.h> |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 NOTREACHED(); | 106 NOTREACHED(); |
| 107 return -1; | 107 return -1; |
| 108 } | 108 } |
| 109 | 109 |
| 110 FilePath GetProcessExecutablePath(ProcessHandle process) { | 110 FilePath GetProcessExecutablePath(ProcessHandle process) { |
| 111 FilePath stat_file("/proc"); | 111 FilePath stat_file("/proc"); |
| 112 stat_file = stat_file.Append(base::IntToString(process)); | 112 stat_file = stat_file.Append(base::IntToString(process)); |
| 113 stat_file = stat_file.Append("exe"); | 113 stat_file = stat_file.Append("exe"); |
| 114 char exename[2048]; | 114 FilePath exe_name; |
| 115 ssize_t len = readlink(stat_file.value().c_str(), exename, sizeof(exename)); | 115 if (!file_util::ReadSymbolicLink(stat_file, &exe_name)) { |
| 116 if (len < 1) { | |
| 117 // No such process. Happens frequently in e.g. TerminateAllChromeProcesses | 116 // No such process. Happens frequently in e.g. TerminateAllChromeProcesses |
| 118 return FilePath(); | 117 return FilePath(); |
| 119 } | 118 } |
| 120 return FilePath(std::string(exename, len)); | 119 return exe_name; |
| 121 } | 120 } |
| 122 | 121 |
| 123 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 122 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
| 124 : filter_(filter) { | 123 : filter_(filter) { |
| 125 procfs_dir_ = opendir("/proc"); | 124 procfs_dir_ = opendir("/proc"); |
| 126 } | 125 } |
| 127 | 126 |
| 128 ProcessIterator::~ProcessIterator() { | 127 ProcessIterator::~ProcessIterator() { |
| 129 if (procfs_dir_) { | 128 if (procfs_dir_) { |
| 130 closedir(procfs_dir_); | 129 closedir(procfs_dir_); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 696 |
| 698 if (!file_util::PathExists(oom_adj)) | 697 if (!file_util::PathExists(oom_adj)) |
| 699 return false; | 698 return false; |
| 700 | 699 |
| 701 std::string score_str = base::IntToString(score); | 700 std::string score_str = base::IntToString(score); |
| 702 return (static_cast<int>(score_str.length()) == | 701 return (static_cast<int>(score_str.length()) == |
| 703 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); | 702 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); |
| 704 } | 703 } |
| 705 | 704 |
| 706 } // namespace base | 705 } // namespace base |
| OLD | NEW |