OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/process_iterator.h" | 5 #include "base/process/process_iterator.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process/internal_linux.h" | 9 #include "base/process/internal_linux.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 *proc_cmd_line_args = SplitString(cmd_line, delimiters, KEEP_WHITESPACE, | 52 *proc_cmd_line_args = SplitString(cmd_line, delimiters, KEEP_WHITESPACE, |
53 SPLIT_WANT_NONEMPTY); | 53 SPLIT_WANT_NONEMPTY); |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 59 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
60 : filter_(filter) { | 60 : filter_(filter) { |
61 procfs_dir_ = opendir(internal::kProcDir); | 61 procfs_dir_ = opendir(internal::kProcDir); |
| 62 if (!procfs_dir_) { |
| 63 // On Android, SELinux may prevent reading /proc. See |
| 64 // https://crbug.com/581517 for details. |
| 65 PLOG(ERROR) << "opendir " << internal::kProcDir; |
| 66 } |
62 } | 67 } |
63 | 68 |
64 ProcessIterator::~ProcessIterator() { | 69 ProcessIterator::~ProcessIterator() { |
65 if (procfs_dir_) { | 70 if (procfs_dir_) { |
66 closedir(procfs_dir_); | 71 closedir(procfs_dir_); |
67 procfs_dir_ = NULL; | 72 procfs_dir_ = nullptr; |
68 } | 73 } |
69 } | 74 } |
70 | 75 |
71 bool ProcessIterator::CheckForNextProcess() { | 76 bool ProcessIterator::CheckForNextProcess() { |
72 // TODO(port): skip processes owned by different UID | 77 // TODO(port): skip processes owned by different UID |
73 | 78 |
| 79 if (!procfs_dir_) { |
| 80 DLOG(ERROR) << "Skipping CheckForNextProcess(), no procfs_dir_"; |
| 81 return false; |
| 82 } |
| 83 |
74 pid_t pid = kNullProcessId; | 84 pid_t pid = kNullProcessId; |
75 std::vector<std::string> cmd_line_args; | 85 std::vector<std::string> cmd_line_args; |
76 std::string stats_data; | 86 std::string stats_data; |
77 std::vector<std::string> proc_stats; | 87 std::vector<std::string> proc_stats; |
78 | 88 |
79 // Arbitrarily guess that there will never be more than 200 non-process | 89 // Arbitrarily guess that there will never be more than 200 non-process |
80 // files in /proc. Hardy has 53 and Lucid has 61. | 90 // files in /proc. Hardy has 53 and Lucid has 61. |
81 int skipped = 0; | 91 int skipped = 0; |
82 const int kSkipLimit = 200; | 92 const int kSkipLimit = 200; |
83 while (skipped < kSkipLimit) { | 93 while (skipped < kSkipLimit) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return true; | 140 return true; |
131 } | 141 } |
132 | 142 |
133 bool NamedProcessIterator::IncludeEntry() { | 143 bool NamedProcessIterator::IncludeEntry() { |
134 if (executable_name_ != entry().exe_file()) | 144 if (executable_name_ != entry().exe_file()) |
135 return false; | 145 return false; |
136 return ProcessIterator::IncludeEntry(); | 146 return ProcessIterator::IncludeEntry(); |
137 } | 147 } |
138 | 148 |
139 } // namespace base | 149 } // namespace base |
OLD | NEW |