OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/linux_util.h" | 5 #include "base/linux_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <glib.h> | 10 #include <glib.h> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 } | 245 } |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 closedir(fd); | 249 closedir(fd); |
250 } | 250 } |
251 | 251 |
252 return already_found; | 252 return already_found; |
253 } | 253 } |
254 | 254 |
255 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data) { | 255 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data, |
256 bool* syscall_supported) { | |
256 char buf[256]; | 257 char buf[256]; |
257 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); | 258 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); |
258 DIR* task = opendir(buf); | 259 DIR* task = opendir(buf); |
259 if (!task) { | 260 if (!task) { |
260 LOG(WARNING) << "Cannot open " << buf; | 261 LOG(WARNING) << "Cannot open " << buf; |
261 return -1; | 262 return -1; |
262 } | 263 } |
263 | 264 |
264 std::vector<pid_t> tids; | 265 std::vector<pid_t> tids; |
265 struct dirent* dent; | 266 struct dirent* dent; |
266 while ((dent = readdir(task))) { | 267 while ((dent = readdir(task))) { |
267 char *endptr; | 268 char *endptr; |
268 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); | 269 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); |
269 if (tid_ul == ULONG_MAX || *endptr) | 270 if (tid_ul == ULONG_MAX || *endptr) |
270 continue; | 271 continue; |
271 tids.push_back(tid_ul); | 272 tids.push_back(tid_ul); |
272 } | 273 } |
273 closedir(task); | 274 closedir(task); |
274 | 275 |
275 scoped_array<char> syscall_data(new char[expected_data.length()]); | 276 scoped_array<char> syscall_data(new char[expected_data.length()]); |
277 *syscall_supported = false; | |
Mark Mentovai
2011/06/21 00:11:24
Can you do this at the very beginning of the funct
kmixter1
2011/06/21 00:55:33
Good catch. Moved it up so that it's always set t
| |
276 for (std::vector<pid_t>::const_iterator | 278 for (std::vector<pid_t>::const_iterator |
277 i = tids.begin(); i != tids.end(); ++i) { | 279 i = tids.begin(); i != tids.end(); ++i) { |
278 const pid_t current_tid = *i; | 280 const pid_t current_tid = *i; |
279 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid); | 281 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid); |
280 int fd = open(buf, O_RDONLY); | 282 int fd = open(buf, O_RDONLY); |
281 if (fd < 0) | 283 if (fd < 0) |
282 continue; | 284 continue; |
285 *syscall_supported = true; | |
283 bool read_ret = | 286 bool read_ret = |
284 file_util::ReadFromFD(fd, syscall_data.get(), expected_data.length()); | 287 file_util::ReadFromFD(fd, syscall_data.get(), expected_data.length()); |
285 close(fd); | 288 close(fd); |
286 if (!read_ret) | 289 if (!read_ret) |
287 continue; | 290 continue; |
288 | 291 |
289 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), | 292 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), |
290 expected_data.length())) { | 293 expected_data.length())) { |
291 return current_tid; | 294 return current_tid; |
292 } | 295 } |
293 } | 296 } |
294 return -1; | 297 return -1; |
295 } | 298 } |
296 | 299 |
297 } // namespace base | 300 } // namespace base |
OLD | NEW |