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 <errno.h> | 7 #include <errno.h> |
8 #include <sys/sysctl.h> | 8 #include <sys/sysctl.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 | 15 |
15 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 16 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
16 : index_of_kinfo_proc_(), | 17 : index_of_kinfo_proc_(), |
17 filter_(filter) { | 18 filter_(filter) { |
18 | 19 |
19 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid(), | 20 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid(), |
20 sizeof(struct kinfo_proc), 0 }; | 21 sizeof(struct kinfo_proc), 0 }; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 DVPLOG(1) << "failed to fetch a commandline"; | 86 DVPLOG(1) << "failed to fetch a commandline"; |
86 continue; | 87 continue; |
87 } | 88 } |
88 | 89 |
89 // |data| contains all the command line parameters of the process, separated | 90 // |data| contains all the command line parameters of the process, separated |
90 // by blocks of one or more null characters. We tokenize |data| into a | 91 // by blocks of one or more null characters. We tokenize |data| into a |
91 // vector of strings using '\0' as a delimiter and populate | 92 // vector of strings using '\0' as a delimiter and populate |
92 // |entry_.cmd_line_args_|. | 93 // |entry_.cmd_line_args_|. |
93 std::string delimiters; | 94 std::string delimiters; |
94 delimiters.push_back('\0'); | 95 delimiters.push_back('\0'); |
95 Tokenize(data, delimiters, &entry_.cmd_line_args_); | 96 entry_.cmd_line_args_ = SplitString(data, delimiters, KEEP_WHITESPACE, |
| 97 SPLIT_WANT_NONEMPTY); |
96 | 98 |
97 // |data| starts with the full executable path followed by a null character. | 99 // |data| starts with the full executable path followed by a null character. |
98 // We search for the first instance of '\0' and extract everything before it | 100 // We search for the first instance of '\0' and extract everything before it |
99 // to populate |entry_.exe_file_|. | 101 // to populate |entry_.exe_file_|. |
100 size_t exec_name_end = data.find('\0'); | 102 size_t exec_name_end = data.find('\0'); |
101 if (exec_name_end == std::string::npos) { | 103 if (exec_name_end == std::string::npos) { |
102 DLOG(ERROR) << "command line data didn't match expected format"; | 104 DLOG(ERROR) << "command line data didn't match expected format"; |
103 continue; | 105 continue; |
104 } | 106 } |
105 | 107 |
(...skipping 13 matching lines...) Expand all Loading... |
119 } | 121 } |
120 return false; | 122 return false; |
121 } | 123 } |
122 | 124 |
123 bool NamedProcessIterator::IncludeEntry() { | 125 bool NamedProcessIterator::IncludeEntry() { |
124 return (executable_name_ == entry().exe_file() && | 126 return (executable_name_ == entry().exe_file() && |
125 ProcessIterator::IncludeEntry()); | 127 ProcessIterator::IncludeEntry()); |
126 } | 128 } |
127 | 129 |
128 } // namespace base | 130 } // namespace base |
OLD | NEW |