Mercurial > minori
annotate dep/animone/src/fd/bsd.cc @ 270:0718f538c5f9
dep/animone: filter open files by access mode
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Fri, 12 Apr 2024 19:13:50 -0400 |
parents | 1a6a5d3a94cd |
children | 65df2813d0de |
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> | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
22 #include <iostream> |
258 | 23 |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
24 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
|
25 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
26 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
|
27 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
|
28 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
29 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
|
30 return name; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
31 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
32 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
|
33 } |
258 | 34 |
35 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
|
36 #ifdef HAVE_KVM_GETFILES |
258 | 37 char errbuf[_POSIX2_LINE_MAX]; |
38 kvm_t* kernel = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); | |
39 if (!kernel) | |
40 return false; | |
41 | |
42 int entries = 0; | |
43 struct kinfo_proc* kinfo = kvm_getprocs(kernel, KERN_PROC_PID, pid, &entries); | |
44 if (!kinfo) { | |
45 kvm_close(kernel); | |
46 return false; | |
47 } | |
48 | |
49 if (entries < 1) { | |
50 kvm_close(kernel); | |
51 return false; | |
52 } | |
53 | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
54 name = Basename(kinfo[0].ki_paddr->p_comm); |
258 | 55 |
56 return true; | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
57 #else |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
58 /* 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
|
59 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
|
60 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
61 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
|
62 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
63 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
|
64 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
|
65 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
66 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
67 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
|
68 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 return true; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
70 #endif |
258 | 71 } |
72 | |
73 /* Most of the BSDs share the common kvm library, | |
74 * so accessing this information can be trivial. | |
75 */ | |
76 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
|
77 #ifdef HAVE_KVM_GETFILES |
258 | 78 char errbuf[_POSIX2_LINE_MAX]; |
79 kvm_t* kernel = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); | |
80 if (!kernel) | |
81 return false; | |
82 | |
83 int entries = 0; | |
84 struct kinfo_proc* kinfo = kvm_getprocs(kernel, KERN_PROC_ALL, 0, &entries); | |
85 if (!kinfo) { | |
86 kvm_close(kernel); | |
87 return false; | |
88 } | |
89 | |
90 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
|
91 if (!process_proc({kinfo[i].ki_paddr->p_pid, Basename(kinfo[i].ki_paddr->p_comm)})) { |
258 | 92 kvm_close(kernel); |
93 return false; | |
94 } | |
95 } | |
96 | |
97 kvm_close(kernel); | |
98 | |
99 return true; | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
100 #else |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
101 /* 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
|
102 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
|
103 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
|
104 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
105 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
|
106 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
107 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
|
108 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
|
109 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
110 if (!result.get()) |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
111 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
112 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
113 /* actually get our results */ |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
114 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
|
115 return false; |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
116 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
117 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
|
118 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
119 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
120 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
|
121 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
|
122 return false; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
123 |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
124 return true; |
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
125 #endif |
258 | 126 } |
127 | |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
128 #ifdef HAVE_KVM_GETFILES |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
129 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
|
130 /* 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
|
131 * to do it ourselves */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
132 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
|
133 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
134 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
|
135 if (!file_system) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
136 return false; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
137 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
138 /* 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
|
139 * kinfo_file structure */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
140 FTSENT* parent = nullptr; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
141 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
|
142 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
|
143 while (child && child->fts_link) { |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
144 child = child->fts_link; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
145 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
|
146 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
147 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
148 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
|
149 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
150 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
151 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
|
152 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
153 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
154 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
|
155 fts_close(file_system); |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
156 return true; |
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 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
160 fts_close(filesystem); |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
161 return false; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
162 } |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
163 #endif /* HAVE_KVM_GETFILES */ |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
164 |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
165 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
|
166 #ifdef HAVE_KVM_GETFILES |
258 | 167 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
|
168 kvm_t* kernel = kvm_openfiles(nullptr, nullptr, nullptr, O_RDONLY, errbuf); |
258 | 169 if (!kernel) |
170 return false; | |
171 | |
172 for (const auto& pid : pids) { | |
173 int cnt; | |
174 struct kinfo_file* kfile = kvm_getfiles(kernel, KERN_FILE_BYPID, pid, &cnt); | |
175 if (!kfile) { | |
176 kvm_close(kernel); | |
177 return false; | |
178 } | |
179 | |
180 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
|
181 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
|
182 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
|
183 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
184 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
185 std::string name; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
186 if (!GetOpenFileName(kfile[i], name)) |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
187 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
188 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
189 if (!open_file_proc({pid, name})) { |
258 | 190 kvm_close(kernel); |
191 return false; | |
192 } | |
193 } | |
194 } | |
195 | |
196 kvm_close(kernel); | |
197 return true; | |
198 #elif defined(LIBUTIL) | |
199 for (const auto& pid : pids) { | |
200 int cnt; | |
201 std::unique_ptr<struct kinfo_file[]> files(kinfo_getfile(pid, &cnt)); | |
202 if (!files) | |
203 return false; | |
204 | |
205 for (int i = 0; i < cnt; i++) { | |
206 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
|
207 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
|
208 continue; |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
209 |
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
210 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
|
211 if (oflags == O_WRONLY || oflags == O_RDWR) |
258 | 212 continue; |
213 | |
214 if (!open_file_proc({pid, current.kf_path})) | |
215 return false; | |
216 } | |
217 } | |
218 | |
219 return true; | |
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
220 #else |
270
0718f538c5f9
dep/animone: filter open files by access mode
Paper <paper@paper.us.eu.org>
parents:
266
diff
changeset
|
221 /* 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
|
222 return false; |
258 | 223 #endif |
224 } | |
225 | |
226 } // namespace animone::internal::kvm |