Mercurial > minori
annotate dep/animone/src/fd/bsd.cc @ 299:246017a7907a
dep/animone: clean up OS X code
GetProcessName() really belongs in fd.cc after removing the
stupid unnecessary LaunchServices code that was stolen from...
some library :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 13 May 2024 14:15:47 -0400 |
parents | 65df2813d0de |
children | b1f625b0227c |
rev | line source |
---|---|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
1 #include "animone/fd/bsd.h" |
258 | 2 #include "animone.h" |
3 #include "animone/fd.h" | |
4 | |
5 #include <sys/file.h> | |
6 #include <sys/filedesc.h> | |
7 #include <sys/param.h> | |
8 #include <sys/queue.h> | |
9 #include <sys/sysctl.h> | |
10 #include <sys/types.h> | |
11 #include <sys/user.h> | |
12 #include <sys/vnode.h> | |
13 | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
14 #ifdef HAVE_KVM_GETFILES |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
15 # include <kvm.h> |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
16 # include <fts.h> |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
17 #elif defined(LIBUTIL) |
258 | 18 # include <libutil.h> |
19 #endif | |
20 | |
21 #include <string> | |
22 | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
23 namespace animone::internal::bsd { |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
24 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
25 static std::string Basename(const std::string& name) { |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
26 size_t s = name.find_last_of('/'); |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
27 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
28 if (s == std::string::npos) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
29 return name; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
30 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
31 return name.substr(s, name.size()); |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
32 } |
258 | 33 |
34 bool GetProcessName(pid_t pid, std::string& name) { | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
35 #ifdef HAVE_KVM_GETFILES |
258 | 36 char errbuf[_POSIX2_LINE_MAX]; |
37 kvm_t* kernel = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); | |
38 if (!kernel) | |
39 return false; | |
40 | |
41 int entries = 0; | |
42 struct kinfo_proc* kinfo = kvm_getprocs(kernel, KERN_PROC_PID, pid, &entries); | |
43 if (!kinfo) { | |
44 kvm_close(kernel); | |
45 return false; | |
46 } | |
47 | |
48 if (entries < 1) { | |
49 kvm_close(kernel); | |
50 return false; | |
51 } | |
52 | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
53 name = Basename(kinfo[0].ki_paddr->p_comm); |
258 | 54 |
55 return true; | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
56 #else |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
57 /* use sysctl as a fallback */ |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
58 static const int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
59 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
60 struct kinfo_proc result; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
61 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
62 size_t length = 1; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
63 if (sysctl((int*)mib, (sizeof(mib) / sizeof(*mib)) - 1, &result, &length, NULL, 0) == -1) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
64 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
65 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
66 name = Basename(result.ki_comm); |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
67 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
68 return true; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 #endif |
258 | 70 } |
71 | |
72 /* Most of the BSDs share the common kvm library, | |
73 * so accessing this information can be trivial. | |
74 */ | |
75 bool EnumerateOpenProcesses(process_proc_t process_proc) { | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
76 #ifdef HAVE_KVM_GETFILES |
258 | 77 char errbuf[_POSIX2_LINE_MAX]; |
78 kvm_t* kernel = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); | |
79 if (!kernel) | |
80 return false; | |
81 | |
82 int entries = 0; | |
83 struct kinfo_proc* kinfo = kvm_getprocs(kernel, KERN_PROC_ALL, 0, &entries); | |
84 if (!kinfo) { | |
85 kvm_close(kernel); | |
86 return false; | |
87 } | |
88 | |
89 for (int i = 0; i < entries; i++) { | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
90 if (!process_proc({kinfo[i].ki_paddr->p_pid, Basename(kinfo[i].ki_paddr->p_comm)})) { |
258 | 91 kvm_close(kernel); |
92 return false; | |
93 } | |
94 } | |
95 | |
96 kvm_close(kernel); | |
97 | |
98 return true; | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
99 #else |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
100 /* use sysctl as a fallback */ |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
101 static const int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
102 size_t length = 0; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
103 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
104 sysctl((int*)mib, (sizeof(mib) / sizeof(*mib)) - 1, NULL, &length, NULL, 0); |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
105 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
106 std::unique_ptr<struct kinfo_proc[]> result; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
107 result.reset(new struct kinfo_proc[length]); |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
108 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
109 if (!result.get()) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
110 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
111 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
112 /* actually get our results */ |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
113 if (sysctl((const int*)mib, (sizeof(mib) / sizeof(*mib)) - 1, result.get(), &length, NULL, 0) == ENOMEM) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
114 return false; |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
115 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
116 if (length < sizeof(struct kinfo_proc)) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
117 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
118 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
119 for (int i = 0; i < length / sizeof(result[0]); i++) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
120 if (!process_proc({result[i].ki_pid, result[i].ki_comm})) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
121 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
122 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
123 return true; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
124 #endif |
258 | 125 } |
126 | |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
127 #ifdef HAVE_KVM_GETFILES |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
128 static bool GetOpenFileName(const struct kinfo_file& file, std::string& name) { |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
129 /* OpenBSD doesn't provide a native API for this, so we have |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
130 * to do it ourselves */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
131 static constexpr std::string_view root = "/"; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
132 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
133 FTS* file_system = fts_open(root.data(), FTS_COMFOLLOW | FTS_NOCHDIR, nullptr); |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
134 if (!file_system) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
135 return false; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
136 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
137 /* Search through the filesystem for a file that matches our |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
138 * kinfo_file structure */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
139 FTSENT* parent = nullptr; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
140 while ((parent = fts_read(file_system))) { |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
141 FTSENT* child = fts_children(file_system, 0); |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
142 while (child && child->fts_link) { |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
143 child = child->fts_link; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
144 if (!S_ISREG(child->fts_statp->st_mode) || !S_ISLNK(child->fts_statp->st_mode)) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
145 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
146 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
147 if (child->fts_statp->st_dev != file->va_fsid) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
148 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
149 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
150 if (child->fts_statp->st_ino != file->va_fileid) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
151 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
152 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
153 name = std::string(child->fts_path) + child->fts_name; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
154 fts_close(file_system); |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
155 return true; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
156 } |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
157 } |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
158 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
159 fts_close(filesystem); |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
160 return false; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
161 } |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
162 #endif /* HAVE_KVM_GETFILES */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
163 |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
164 bool EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) { |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
165 #ifdef HAVE_KVM_GETFILES |
258 | 166 char errbuf[_POSIX2_LINE_MAX]; |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
167 kvm_t* kernel = kvm_openfiles(nullptr, nullptr, nullptr, O_RDONLY, errbuf); |
258 | 168 if (!kernel) |
169 return false; | |
170 | |
171 for (const auto& pid : pids) { | |
172 int cnt; | |
173 struct kinfo_file* kfile = kvm_getfiles(kernel, KERN_FILE_BYPID, pid, &cnt); | |
174 if (!kfile) { | |
175 kvm_close(kernel); | |
176 return false; | |
177 } | |
178 | |
179 for (int i = 0; i < cnt; i++) { | |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
180 uint32_t oflags = kfile[i].kf_flags & O_ACCMODE; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
181 if (oflags == O_WRONLY || oflags == O_RDWR) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
182 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
183 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
184 std::string name; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
185 if (!GetOpenFileName(kfile[i], name)) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
186 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
187 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
188 if (!open_file_proc({pid, name})) { |
258 | 189 kvm_close(kernel); |
190 return false; | |
191 } | |
192 } | |
193 } | |
194 | |
195 kvm_close(kernel); | |
196 return true; | |
197 #elif defined(LIBUTIL) | |
198 for (const auto& pid : pids) { | |
199 int cnt; | |
200 std::unique_ptr<struct kinfo_file[]> files(kinfo_getfile(pid, &cnt)); | |
201 if (!files) | |
202 return false; | |
203 | |
204 for (int i = 0; i < cnt; i++) { | |
205 const struct kinfo_file& current = files[i]; | |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
206 if (current.kf_vnode_type != KF_VTYPE_VREG || current.kf_vnode_type != KF_VTYPE_VLNK) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
207 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
208 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
209 const int oflags = current.kf_flags & O_ACCMODE; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
210 if (oflags == O_WRONLY || oflags == O_RDWR) |
258 | 211 continue; |
212 | |
213 if (!open_file_proc({pid, current.kf_path})) | |
214 return false; | |
215 } | |
216 } | |
217 | |
218 return true; | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
219 #else |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
220 /* NetBSD doesn't even provide a real API for this */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
221 return false; |
258 | 222 #endif |
223 } | |
224 | |
225 } // namespace animone::internal::kvm |