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 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 | 17 |
17 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 18 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
18 : index_of_kinfo_proc_(0), | 19 : index_of_kinfo_proc_(0), |
19 filter_(filter) { | 20 filter_(filter) { |
20 // Get a snapshot of all of my processes (yes, as we loop it can go stale, but | 21 // Get a snapshot of all of my processes (yes, as we loop it can go stale, but |
21 // but trying to find where we were in a constantly changing list is basically | 22 // but trying to find where we were in a constantly changing list is basically |
22 // impossible. | 23 // impossible. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 DVPLOG(1) << "failed to fetch a commandline"; | 93 DVPLOG(1) << "failed to fetch a commandline"; |
93 continue; | 94 continue; |
94 } | 95 } |
95 | 96 |
96 // |data| contains all the command line parameters of the process, separated | 97 // |data| contains all the command line parameters of the process, separated |
97 // by blocks of one or more null characters. We tokenize |data| into a | 98 // by blocks of one or more null characters. We tokenize |data| into a |
98 // vector of strings using '\0' as a delimiter and populate | 99 // vector of strings using '\0' as a delimiter and populate |
99 // |entry_.cmd_line_args_|. | 100 // |entry_.cmd_line_args_|. |
100 std::string delimiters; | 101 std::string delimiters; |
101 delimiters.push_back('\0'); | 102 delimiters.push_back('\0'); |
102 Tokenize(data, delimiters, &entry_.cmd_line_args_); | 103 entry_.cmd_line_args_ = SplitString(data, delimiters, |
| 104 KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY); |
103 | 105 |
104 // |data| starts with the full executable path followed by a null character. | 106 // |data| starts with the full executable path followed by a null character. |
105 // We search for the first instance of '\0' and extract everything before it | 107 // We search for the first instance of '\0' and extract everything before it |
106 // to populate |entry_.exe_file_|. | 108 // to populate |entry_.exe_file_|. |
107 size_t exec_name_end = data.find('\0'); | 109 size_t exec_name_end = data.find('\0'); |
108 if (exec_name_end == std::string::npos) { | 110 if (exec_name_end == std::string::npos) { |
109 DLOG(ERROR) << "command line data didn't match expected format"; | 111 DLOG(ERROR) << "command line data didn't match expected format"; |
110 continue; | 112 continue; |
111 } | 113 } |
112 | 114 |
(...skipping 13 matching lines...) Expand all Loading... |
126 } | 128 } |
127 return false; | 129 return false; |
128 } | 130 } |
129 | 131 |
130 bool NamedProcessIterator::IncludeEntry() { | 132 bool NamedProcessIterator::IncludeEntry() { |
131 return (executable_name_ == entry().exe_file() && | 133 return (executable_name_ == entry().exe_file() && |
132 ProcessIterator::IncludeEntry()); | 134 ProcessIterator::IncludeEntry()); |
133 } | 135 } |
134 | 136 |
135 } // namespace base | 137 } // namespace base |
OLD | NEW |