| @@ -1,38 +1,46 @@ | | | @@ -1,38 +1,46 @@ |
1 | $NetBSD: patch-src_task-manager-bsd.c,v 1.1 2015/04/21 08:56:41 jperkin Exp $ | | 1 | $NetBSD: patch-src_task-manager-bsd.c,v 1.2 2016/01/28 12:47:00 martin Exp $ |
2 | | | 2 | |
3 | Attempt to bring netbsd, DragonFly while keeping OpenBSD support. | | 3 | Attempt to bring netbsd, DragonFly while keeping OpenBSD support. |
4 | --- src/task-manager-bsd.c.orig 2014-12-23 20:40:14.000000000 +0000 | | 4 | --- src/task-manager-bsd.c.orig 2014-12-23 21:40:14.000000000 +0100 |
5 | +++ src/task-manager-bsd.c | | 5 | +++ src/task-manager-bsd.c 2016-01-28 13:44:44.128899084 +0100 |
6 | @@ -25,8 +25,18 @@ | | 6 | @@ -16,6 +16,7 @@ |
| | | 7 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| | | 8 | */ |
| | | 9 | |
| | | 10 | +#define _KMEMUSER /* NetBSD hides many types for regular userland */ |
| | | 11 | #include <stdlib.h> |
| | | 12 | #include <err.h> |
| | | 13 | /* for getpwuid() */ |
| | | 14 | @@ -25,8 +26,18 @@ |
7 | #include <sys/param.h> | | 15 | #include <sys/param.h> |
8 | #include <sys/sched.h> | | 16 | #include <sys/sched.h> |
9 | #include <sys/sysctl.h> | | 17 | #include <sys/sysctl.h> |
10 | + | | 18 | + |
11 | +#ifdef __DragonFly__ | | 19 | +#ifdef __DragonFly__ |
12 | +#include <sys/kinfo.h> | | 20 | +#include <sys/kinfo.h> |
13 | +#include <sys/resource.h> | | 21 | +#include <sys/resource.h> |
14 | +#include <vm/vm_param.h> | | 22 | +#include <vm/vm_param.h> |
15 | +#else | | 23 | +#else |
16 | /* for swapctl() */ | | 24 | /* for swapctl() */ |
17 | #include <sys/swap.h> | | 25 | #include <sys/swap.h> |
18 | +#include <uvm/uvm_extern.h> | | 26 | +#include <uvm/uvm_extern.h> |
19 | +#endif | | 27 | +#endif |
20 | + | | 28 | + |
21 | +#include <kvm.h> | | 29 | +#include <kvm.h> |
22 | /* for strlcpy() */ | | 30 | /* for strlcpy() */ |
23 | #include <string.h> | | 31 | #include <string.h> |
24 | /* for getpagesize() */ | | 32 | /* for getpagesize() */ |
25 | @@ -46,108 +56,107 @@ char *state_abbrev[] = { | | 33 | @@ -46,108 +57,107 @@ char *state_abbrev[] = { |
26 | | | 34 | |
27 | gboolean get_task_list (GArray *task_list) | | 35 | gboolean get_task_list (GArray *task_list) |
28 | { | | 36 | { |
29 | - int mib[6]; | | 37 | - int mib[6]; |
30 | - size_t size; | | 38 | - size_t size; |
31 | -#ifdef __OpenBSD__ | | 39 | -#ifdef __OpenBSD__ |
32 | - struct kinfo_proc *kp; | | 40 | - struct kinfo_proc *kp; |
33 | -#else | | 41 | -#else |
34 | - struct kinfo_proc2 *kp; | | 42 | - struct kinfo_proc2 *kp; |
35 | -#endif | | 43 | -#endif |
36 | - Task t; | | 44 | - Task t; |
37 | - struct passwd *passwdp; | | 45 | - struct passwd *passwdp; |
38 | - char **args; | | 46 | - char **args; |
| @@ -219,27 +227,27 @@ Attempt to bring netbsd, DragonFly while | | | @@ -219,27 +227,27 @@ Attempt to bring netbsd, DragonFly while |
219 | + passwdp = getpwuid(t.uid); | | 227 | + passwdp = getpwuid(t.uid); |
220 | + if (passwdp != NULL && passwdp->pw_name != NULL) | | 228 | + if (passwdp != NULL && passwdp->pw_name != NULL) |
221 | + g_strlcpy(t.uid_name, passwdp->pw_name, | | 229 | + g_strlcpy(t.uid_name, passwdp->pw_name, |
222 | + sizeof(t.uid_name)); | | 230 | + sizeof(t.uid_name)); |
223 | + g_array_append_val(task_list, t); | | 231 | + g_array_append_val(task_list, t); |
224 | + } | | 232 | + } |
225 | + } | | 233 | + } |
226 | + g_free(args); | | 234 | + g_free(args); |
227 | + g_free(buf); | | 235 | + g_free(buf); |
228 | + g_free(kp); | | 236 | + g_free(kp); |
229 | | | 237 | |
230 | return TRUE; | | 238 | return TRUE; |
231 | } | | 239 | } |
232 | @@ -156,26 +165,26 @@ gboolean | | 240 | @@ -156,26 +166,26 @@ gboolean |
233 | pid_is_sleeping (guint pid) | | 241 | pid_is_sleeping (guint pid) |
234 | { | | 242 | { |
235 | int mib[6]; | | 243 | int mib[6]; |
236 | -#ifdef __OpenBSD__ | | 244 | -#ifdef __OpenBSD__ |
237 | - struct kinfo_proc kp; | | 245 | - struct kinfo_proc kp; |
238 | - size_t size = sizeof(struct kinfo_proc); | | 246 | - size_t size = sizeof(struct kinfo_proc); |
239 | -#else | | 247 | -#else |
240 | +#ifdef __NetBSD__ | | 248 | +#ifdef __NetBSD__ |
241 | struct kinfo_proc2 kp; | | 249 | struct kinfo_proc2 kp; |
242 | size_t size = sizeof(struct kinfo_proc2); | | 250 | size_t size = sizeof(struct kinfo_proc2); |
243 | +#else | | 251 | +#else |
244 | + struct kinfo_proc kp; | | 252 | + struct kinfo_proc kp; |
245 | + size_t size = sizeof(struct kinfo_proc); | | 253 | + size_t size = sizeof(struct kinfo_proc); |
| @@ -256,39 +264,39 @@ Attempt to bring netbsd, DragonFly while | | | @@ -256,39 +264,39 @@ Attempt to bring netbsd, DragonFly while |
256 | #endif | | 264 | #endif |
257 | mib[2] = KERN_PROC_PID; | | 265 | mib[2] = KERN_PROC_PID; |
258 | mib[3] = pid; | | 266 | mib[3] = pid; |
259 | -#ifdef __OpenBSD__ | | 267 | -#ifdef __OpenBSD__ |
260 | - mib[4] = sizeof(struct kinfo_proc); | | 268 | - mib[4] = sizeof(struct kinfo_proc); |
261 | -#else | | 269 | -#else |
262 | +#ifdef __NetBSD__ | | 270 | +#ifdef __NetBSD__ |
263 | mib[4] = sizeof(struct kinfo_proc2); | | 271 | mib[4] = sizeof(struct kinfo_proc2); |
264 | +#else | | 272 | +#else |
265 | + mib[4] = sizeof(struct kinfo_proc); | | 273 | + mib[4] = sizeof(struct kinfo_proc); |
266 | #endif | | 274 | #endif |
267 | mib[5] = 1; | | 275 | mib[5] = 1; |
268 | if (sysctl(mib, 6, &kp, &size, NULL, 0) < 0) | | 276 | if (sysctl(mib, 6, &kp, &size, NULL, 0) < 0) |
269 | @@ -184,7 +193,11 @@ pid_is_sleeping (guint pid) | | 277 | @@ -184,7 +194,11 @@ pid_is_sleeping (guint pid) |
270 | #else | | 278 | #else |
271 | errx(1, "could not read kern.proc2 for pid %d", pid); | | 279 | errx(1, "could not read kern.proc2 for pid %d", pid); |
272 | #endif | | 280 | #endif |
273 | +#ifdef __DragonFly__ | | 281 | +#ifdef __DragonFly__ |
274 | + return (kp.kp_stat == SSTOP ? TRUE : FALSE); | | 282 | + return (kp.kp_stat == SSTOP ? TRUE : FALSE); |
275 | +#else | | 283 | +#else |
276 | return (kp.p_stat == SSTOP ? TRUE : FALSE); | | 284 | return (kp.p_stat == SSTOP ? TRUE : FALSE); |
277 | +#endif | | 285 | +#endif |
278 | } | | 286 | } |
279 | | | 287 | |
280 | gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) | | 288 | gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) |
281 | @@ -192,12 +205,31 @@ gboolean get_cpu_usage (gushort *cpu_cou | | 289 | @@ -192,12 +206,31 @@ gboolean get_cpu_usage (gushort *cpu_cou |
282 | static gulong cur_user = 0, cur_system = 0, cur_total = 0; | | 290 | static gulong cur_user = 0, cur_system = 0, cur_total = 0; |
283 | static gulong old_user = 0, old_system = 0, old_total = 0; | | 291 | static gulong old_user = 0, old_system = 0, old_total = 0; |
284 | | | 292 | |
285 | - int mib[] = {CTL_KERN, KERN_CPTIME}; | | 293 | - int mib[] = {CTL_KERN, KERN_CPTIME}; |
286 | - glong cp_time[CPUSTATES]; | | 294 | - glong cp_time[CPUSTATES]; |
287 | - gsize size = sizeof( cp_time ); | | 295 | - gsize size = sizeof( cp_time ); |
288 | +#if defined(__DragonFly__) | | 296 | +#if defined(__DragonFly__) |
289 | + int mib[2]; | | 297 | + int mib[2]; |
290 | + struct kinfo_cputime percpu; | | 298 | + struct kinfo_cputime percpu; |
291 | + size_t size = sizeof(percpu); | | 299 | + size_t size = sizeof(percpu); |
292 | + uint64_t cp_time[CPUSTATES]; | | 300 | + uint64_t cp_time[CPUSTATES]; |
293 | + | | 301 | + |
294 | + if (sysctlbyname("kern.cputime", &percpu, &size, NULL, 0) < 0) | | 302 | + if (sysctlbyname("kern.cputime", &percpu, &size, NULL, 0) < 0) |
| @@ -304,27 +312,27 @@ Attempt to bring netbsd, DragonFly while | | | @@ -304,27 +312,27 @@ Attempt to bring netbsd, DragonFly while |
304 | + int mib[] = {CTL_KERN, KERN_CP_TIME}; | | 312 | + int mib[] = {CTL_KERN, KERN_CP_TIME}; |
305 | +#else | | 313 | +#else |
306 | + int mib[] = {CTL_KERN, KERN_CPTIME}; | | 314 | + int mib[] = {CTL_KERN, KERN_CPTIME}; |
307 | +#endif | | 315 | +#endif |
308 | + glong cp_time[CPUSTATES]; | | 316 | + glong cp_time[CPUSTATES]; |
309 | + gsize size = sizeof( cp_time ); | | 317 | + gsize size = sizeof( cp_time ); |
310 | if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0) | | 318 | if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0) |
311 | errx(1,"failed to get kern.cptime"); | | 319 | errx(1,"failed to get kern.cptime"); |
312 | - | | 320 | - |
313 | +#endif | | 321 | +#endif |
314 | old_user = cur_user; | | 322 | old_user = cur_user; |
315 | old_system = cur_system; | | 323 | old_system = cur_system; |
316 | old_total = cur_total; | | 324 | old_total = cur_total; |
317 | @@ -217,65 +249,72 @@ gboolean get_cpu_usage (gushort *cpu_cou | | 325 | @@ -217,65 +250,72 @@ gboolean get_cpu_usage (gushort *cpu_cou |
318 | errx(1,"failed to get cpu count"); | | 326 | errx(1,"failed to get cpu count"); |
319 | return TRUE; | | 327 | return TRUE; |
320 | } | | 328 | } |
321 | - | | 329 | - |
322 | /* vmtotal values in #pg */ | | 330 | /* vmtotal values in #pg */ |
323 | #define pagetok(nb) ((nb) * (getpagesize())) | | 331 | #define pagetok(nb) ((nb) * (getpagesize())) |
324 | | | 332 | |
325 | gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free) | | 333 | gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free) |
326 | { | | 334 | { |
327 | #ifdef __OpenBSD__ | | 335 | #ifdef __OpenBSD__ |
328 | - int mib[] = {CTL_VM, VM_UVMEXP}; | | 336 | - int mib[] = {CTL_VM, VM_UVMEXP}; |
329 | - struct uvmexp uvmexp; | | 337 | - struct uvmexp uvmexp; |
330 | + int mib[] = {CTL_VM, VM_UVMEXP}; | | 338 | + int mib[] = {CTL_VM, VM_UVMEXP}; |