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 <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/sysctl.h> | 8 #include <sys/sysctl.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 | 16 |
16 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 17 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
17 : index_of_kinfo_proc_(), | 18 : index_of_kinfo_proc_(), |
18 filter_(filter) { | 19 filter_(filter) { |
19 | 20 |
20 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid() }; | 21 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid() }; |
21 | 22 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 82 |
82 data.resize(length); | 83 data.resize(length); |
83 | 84 |
84 if (sysctl(mib, arraysize(mib), &data[0], &length, NULL, 0) < 0) { | 85 if (sysctl(mib, arraysize(mib), &data[0], &length, NULL, 0) < 0) { |
85 LOG(ERROR) << "failed to fetch a commandline"; | 86 LOG(ERROR) << "failed to fetch a commandline"; |
86 continue; | 87 continue; |
87 } | 88 } |
88 | 89 |
89 std::string delimiters; | 90 std::string delimiters; |
90 delimiters.push_back('\0'); | 91 delimiters.push_back('\0'); |
91 Tokenize(data, delimiters, &entry_.cmd_line_args_); | 92 entry_.cmd_line_args_ = SplitString(data, delimiters, |
| 93 KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY); |
92 | 94 |
93 size_t exec_name_end = data.find('\0'); | 95 size_t exec_name_end = data.find('\0'); |
94 if (exec_name_end == std::string::npos) { | 96 if (exec_name_end == std::string::npos) { |
95 LOG(ERROR) << "command line data didn't match expected format"; | 97 LOG(ERROR) << "command line data didn't match expected format"; |
96 continue; | 98 continue; |
97 } | 99 } |
98 | 100 |
99 entry_.pid_ = kinfo.ki_pid; | 101 entry_.pid_ = kinfo.ki_pid; |
100 entry_.ppid_ = kinfo.ki_ppid; | 102 entry_.ppid_ = kinfo.ki_ppid; |
101 entry_.gid_ = kinfo.ki_pgid; | 103 entry_.gid_ = kinfo.ki_pgid; |
(...skipping 15 matching lines...) Expand all Loading... |
117 } | 119 } |
118 | 120 |
119 bool NamedProcessIterator::IncludeEntry() { | 121 bool NamedProcessIterator::IncludeEntry() { |
120 if (executable_name_ != entry().exe_file()) | 122 if (executable_name_ != entry().exe_file()) |
121 return false; | 123 return false; |
122 | 124 |
123 return ProcessIterator::IncludeEntry(); | 125 return ProcessIterator::IncludeEntry(); |
124 } | 126 } |
125 | 127 |
126 } // namespace base | 128 } // namespace base |
OLD | NEW |