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/process_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <dirent.h> | 8 #include <dirent.h> |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 mib[5] = (length / sizeof(struct kinfo_proc)); | 41 mib[5] = (length / sizeof(struct kinfo_proc)); |
42 | 42 |
43 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) | 43 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) |
44 return -1; | 44 return -1; |
45 | 45 |
46 return info.p_ppid; | 46 return info.p_ppid; |
47 } | 47 } |
48 | 48 |
49 FilePath GetProcessExecutablePath(ProcessHandle process) { | 49 FilePath GetProcessExecutablePath(ProcessHandle process) { |
50 return FilePath(std::string("/usr/local/chrome/chrome")); | 50 struct kinfo_proc kp; |
| 51 size_t len; |
| 52 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process, |
| 53 sizeof(struct kinfo_proc), 0 }; |
| 54 |
| 55 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) == -1) |
| 56 return FilePath(); |
| 57 mib[5] = (len / sizeof(struct kinfo_proc)); |
| 58 if (sysctl(mib, arraysize(mib), &kp, &len, NULL, 0) < 0) |
| 59 return FilePath(); |
| 60 if ((kp.p_flag & P_SYSTEM) != 0) |
| 61 return FilePath(); |
| 62 if (strcmp(kp.p_comm, "chrome") == 0) |
| 63 return FilePath(kp.p_comm); |
| 64 |
| 65 return FilePath(); |
51 } | 66 } |
52 | 67 |
53 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 68 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
54 : index_of_kinfo_proc_(), | 69 : index_of_kinfo_proc_(), |
55 filter_(filter) { | 70 filter_(filter) { |
56 | 71 |
57 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid(), | 72 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid(), |
58 sizeof(struct kinfo_proc), 0 }; | 73 sizeof(struct kinfo_proc), 0 }; |
59 | 74 |
60 bool done = false; | 75 bool done = false; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); | 337 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); |
323 } | 338 } |
324 | 339 |
325 void EnableTerminationOnOutOfMemory() { | 340 void EnableTerminationOnOutOfMemory() { |
326 } | 341 } |
327 | 342 |
328 void EnableTerminationOnHeapCorruption() { | 343 void EnableTerminationOnHeapCorruption() { |
329 } | 344 } |
330 | 345 |
331 } // namespace base | 346 } // namespace base |
OLD | NEW |