Mercurial > minori
comparison dep/animia/src/fd/xnu.cc @ 154:d43d68408d3c
dep/animia: fix XnuFdTools
also we use anitomy directly now.
HG Enter commit message. Lines beginning with 'HG:' are removed.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 15 Nov 2023 14:14:17 -0500 |
parents | bd439dd6ffc5 |
children | d2bbb5773616 |
comparison
equal
deleted
inserted
replaced
153:bd439dd6ffc5 | 154:d43d68408d3c |
---|---|
6 #include "animia.h" | 6 #include "animia.h" |
7 | 7 |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <vector> | 9 #include <vector> |
10 #include <string> | 10 #include <string> |
11 #include <cassert> | |
11 | 12 |
12 #include <fcntl.h> | 13 #include <fcntl.h> |
13 #include <sys/sysctl.h> | 14 #include <sys/sysctl.h> |
14 #include <sys/types.h> | 15 #include <sys/types.h> |
15 #include <sys/user.h> | 16 #include <sys/user.h> |
16 #include <libproc.h> | 17 #include <libproc.h> |
17 | 18 |
18 namespace animia::internal::xnu { | 19 namespace animia::internal::xnu { |
19 | 20 |
20 static bool GetProcessName(pid_t pid, std::string& result) { | 21 static std::string GetProcessName(pid_t pid) { |
21 struct proc_bsdinfo proc; | 22 struct proc_bsdinfo proc; |
22 | 23 |
23 int st = proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE); | 24 int st = proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE); |
24 if (st != PROC_PIDTBSDINFO_SIZE) | 25 if (st != PROC_PIDTBSDINFO_SIZE) |
25 return false; | 26 return ""; |
26 | 27 |
27 /* fixme: is this right? pbi_comm is an alternative, but it reduces the string size to | 28 /* fixme: is this right? pbi_comm is an alternative, but it reduces the string size to |
28 16 chars. does pbi_name do the same, or is it different? */ | 29 16 chars. does pbi_name do the same, or is it different? */ |
29 result = proc.pbi_name; | 30 return proc.pbi_name; |
30 return true; | |
31 } | 31 } |
32 | 32 |
33 /* this is a cleaned up version of a function from... Apple? | 33 /* this is a cleaned up version of a function from... Apple? |
34 ...anyway, what it essentially does is gets the size and stuff from | 34 ...anyway, what it essentially does is gets the size and stuff from |
35 sysctl() and reserves the space in a vector to store the PIDs */ | 35 sysctl() and reserves the space in a vector to store the PIDs */ |
58 for (int i = 0; i < length / sizeof(*result); i++) { | 58 for (int i = 0; i < length / sizeof(*result); i++) { |
59 const pid_t pid = result[i].kp_proc.p_pid; | 59 const pid_t pid = result[i].kp_proc.p_pid; |
60 if (!process_proc({pid, GetProcessName(pid)})) | 60 if (!process_proc({pid, GetProcessName(pid)})) |
61 return false; | 61 return false; |
62 } | 62 } |
63 | |
64 return true; | |
63 } | 65 } |
64 | 66 |
65 bool XnuFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) { | 67 bool XnuFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) { |
66 if (!open_file_proc) | 68 if (!open_file_proc) |
67 return false; | 69 return false; |
93 if (!open_file_proc({pid, vnodeInfo.pvip.vip_path})) | 95 if (!open_file_proc({pid, vnodeInfo.pvip.vip_path})) |
94 return false; | 96 return false; |
95 } | 97 } |
96 } | 98 } |
97 } | 99 } |
100 | |
98 return true; | 101 return true; |
99 } | 102 } |
100 | 103 |
101 } // namespace animia::internal::unix | 104 } // namespace animia::internal::unix |