Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <glib.h> | 10 #include <glib.h> |
| 10 #include <stdlib.h> | 11 #include <stdlib.h> |
| 11 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 13 #include <sys/stat.h> | |
| 14 #include <sys/types.h> | |
| 12 #include <unistd.h> | 15 #include <unistd.h> |
| 13 | 16 |
| 14 #include <vector> | 17 #include <vector> |
| 15 | 18 |
| 16 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 17 #include "base/env_var.h" | 20 #include "base/env_var.h" |
| 21 #include "base/file_util.h" | |
| 18 #include "base/lock.h" | 22 #include "base/lock.h" |
| 19 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 20 #include "base/process_util.h" | 24 #include "base/process_util.h" |
| 21 #include "base/singleton.h" | 25 #include "base/singleton.h" |
| 26 #include "base/scoped_ptr.h" | |
| 22 #include "base/string_util.h" | 27 #include "base/string_util.h" |
| 23 | 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 // Not needed for OS_CHROMEOS. | 31 // Not needed for OS_CHROMEOS. |
| 27 #if defined(OS_LINUX) | 32 #if defined(OS_LINUX) |
| 28 enum LinuxDistroState { | 33 enum LinuxDistroState { |
| 29 STATE_DID_NOT_CHECK = 0, | 34 STATE_DID_NOT_CHECK = 0, |
| 30 STATE_CHECK_STARTED = 1, | 35 STATE_CHECK_STARTED = 1, |
| 31 STATE_CHECK_FINISHED = 2, | 36 STATE_CHECK_FINISHED = 2, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 239 } |
| 235 } | 240 } |
| 236 } | 241 } |
| 237 | 242 |
| 238 closedir(fd); | 243 closedir(fd); |
| 239 } | 244 } |
| 240 | 245 |
| 241 return already_found; | 246 return already_found; |
| 242 } | 247 } |
| 243 | 248 |
| 249 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data) { | |
| 250 char buf[256]; | |
| 251 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); | |
| 252 DIR* task = opendir(buf); | |
| 253 if (!task) { | |
| 254 LOG(WARNING) << "Cannot open " << buf; | |
| 255 return -1; | |
| 256 } | |
| 257 | |
| 258 std::vector<pid_t> tids; | |
| 259 struct dirent* dent; | |
| 260 while ((dent = readdir(task))) { | |
| 261 char *endptr; | |
| 262 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); | |
| 263 if (tid_ul == ULONG_MAX || *endptr) | |
| 264 continue; | |
| 265 tids.push_back(tid_ul); | |
| 266 } | |
| 267 closedir(task); | |
| 268 | |
| 269 scoped_array<char> syscall_data(new char[expected_data.length()]); | |
| 270 for (std::vector<pid_t>::const_iterator | |
| 271 i = tids.begin(); i != tids.end(); ++i) { | |
| 272 const pid_t current_tid = *i; | |
| 273 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid); | |
| 274 int fd = open(buf, O_RDONLY); | |
| 275 if (fd < 0) | |
| 276 continue; | |
| 277 bool read_ret = | |
| 278 file_util::ReadFromFD(fd, syscall_data.get(), expected_data.length()); | |
| 279 close(fd); | |
| 280 if (!read_ret) | |
| 281 continue; | |
| 282 | |
| 283 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), | |
|
agl
2010/07/16 12:43:25
Based on the description of the function, I expect
| |
| 284 expected_data.length())) { | |
| 285 return current_tid; | |
| 286 } | |
| 287 } | |
| 288 return -1; | |
| 289 } | |
| 290 | |
| 244 } // namespace base | 291 } // namespace base |
| OLD | NEW |