OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/process_util.h" | |
6 | |
7 #include <ctype.h> | |
8 #include <dirent.h> | |
9 #include <dlfcn.h> | |
10 #include <errno.h> | |
11 #include <fcntl.h> | |
12 #include <sys/param.h> | |
13 #include <sys/sysctl.h> | |
14 #include <sys/time.h> | |
15 #include <sys/types.h> | |
16 #include <sys/user.h> | |
17 #include <sys/wait.h> | |
18 #include <time.h> | |
19 #include <unistd.h> | |
20 | |
21 #include "base/logging.h" | |
22 #include "base/string_tokenizer.h" | |
23 #include "base/strings/string_number_conversions.h" | |
24 #include "base/strings/string_split.h" | |
25 #include "base/strings/string_util.h" | |
26 #include "base/sys_info.h" | |
27 #include "base/threading/thread_restrictions.h" | |
28 | |
29 namespace base { | |
30 | |
31 ProcessId GetParentProcessId(ProcessHandle process) { | |
32 struct kinfo_proc info; | |
33 size_t length; | |
34 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process, | |
35 sizeof(struct kinfo_proc), 0 }; | |
36 | |
37 if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0) | |
38 return -1; | |
39 | |
40 mib[5] = (length / sizeof(struct kinfo_proc)); | |
41 | |
42 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) | |
43 return -1; | |
44 | |
45 return info.p_ppid; | |
46 } | |
47 | |
48 FilePath GetProcessExecutablePath(ProcessHandle process) { | |
49 struct kinfo_proc kp; | |
50 size_t len; | |
51 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process, | |
52 sizeof(struct kinfo_proc), 0 }; | |
53 | |
54 if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) == -1) | |
55 return FilePath(); | |
56 mib[5] = (len / sizeof(struct kinfo_proc)); | |
57 if (sysctl(mib, arraysize(mib), &kp, &len, NULL, 0) < 0) | |
58 return FilePath(); | |
59 if ((kp.p_flag & P_SYSTEM) != 0) | |
60 return FilePath(); | |
61 if (strcmp(kp.p_comm, "chrome") == 0) | |
62 return FilePath(kp.p_comm); | |
63 | |
64 return FilePath(); | |
65 } | |
66 | |
67 } // namespace base | |
OLD | NEW |