Thu Jan 28 12:47:00 2016 UTC ()
Make it work in NetBSD-current (where vsize_t is hidden from regular userland)


(martin)
diff -r1.2 -r1.3 pkgsrc/sysutils/xfce4-taskmanager/distinfo
diff -r1.1 -r1.2 pkgsrc/sysutils/xfce4-taskmanager/patches/patch-src_task-manager-bsd.c

cvs diff -r1.2 -r1.3 pkgsrc/sysutils/xfce4-taskmanager/distinfo (switch to unified diff)

--- pkgsrc/sysutils/xfce4-taskmanager/distinfo 2015/11/04 01:32:41 1.2
+++ pkgsrc/sysutils/xfce4-taskmanager/distinfo 2016/01/28 12:47:00 1.3
@@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
1$NetBSD: distinfo,v 1.2 2015/11/04 01:32:41 agc Exp $ 1$NetBSD: distinfo,v 1.3 2016/01/28 12:47:00 martin Exp $
2 2
3SHA1 (xfce4-taskmanager-1.1.0.tar.bz2) = 4a45d19169fab4270250633a46cfb5be536c3cd7 3SHA1 (xfce4-taskmanager-1.1.0.tar.bz2) = 4a45d19169fab4270250633a46cfb5be536c3cd7
4RMD160 (xfce4-taskmanager-1.1.0.tar.bz2) = 4c22f73fbafa40674281a4719ac71de1a591d210 4RMD160 (xfce4-taskmanager-1.1.0.tar.bz2) = 4c22f73fbafa40674281a4719ac71de1a591d210
5SHA512 (xfce4-taskmanager-1.1.0.tar.bz2) = a7b1d1a6836f89747c873c87e495830438cf3093fd044c43c951abca6a82ab2c0ae9a41eba89d570a83f41fb6ad447c9c4fc578930684c981fbe45de19e1d7f8 5SHA512 (xfce4-taskmanager-1.1.0.tar.bz2) = a7b1d1a6836f89747c873c87e495830438cf3093fd044c43c951abca6a82ab2c0ae9a41eba89d570a83f41fb6ad447c9c4fc578930684c981fbe45de19e1d7f8
6Size (xfce4-taskmanager-1.1.0.tar.bz2) = 365866 bytes 6Size (xfce4-taskmanager-1.1.0.tar.bz2) = 365866 bytes
7SHA1 (patch-src_task-manager-bsd.c) = 0b93dccd43d56b36da951710e39c0da426933b19 7SHA1 (patch-src_task-manager-bsd.c) = 5cc8bb3c949512c543eaf461fb78af573b639de9

cvs diff -r1.1 -r1.2 pkgsrc/sysutils/xfce4-taskmanager/patches/Attic/patch-src_task-manager-bsd.c (switch to unified diff)

--- pkgsrc/sysutils/xfce4-taskmanager/patches/Attic/patch-src_task-manager-bsd.c 2015/04/21 08:56:41 1.1
+++ pkgsrc/sysutils/xfce4-taskmanager/patches/Attic/patch-src_task-manager-bsd.c 2016/01/28 12:47:00 1.2
@@ -1,441 +1,449 @@ @@ -1,441 +1,449 @@
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
3Attempt to bring netbsd, DragonFly while keeping OpenBSD support. 3Attempt 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;
39- gchar* buf; 47- gchar* buf;
40- int nproc, i; 48- int nproc, i;
41+ Task t; 49+ Task t;
42+#ifdef __NetBSD__ 50+#ifdef __NetBSD__
43+ struct kinfo_proc2 *kp = NULL; 51+ struct kinfo_proc2 *kp = NULL;
44+#else 52+#else
45+ struct kinfo_proc *kp = NULL; 53+ struct kinfo_proc *kp = NULL;
46+#endif 54+#endif
47+ 55+
48+ struct passwd *passwdp; 56+ struct passwd *passwdp;
49+ char **args = NULL; 57+ char **args = NULL;
50+ char *buf = NULL; 58+ char *buf = NULL;
51+ unsigned int i = 0; 59+ unsigned int i = 0;
52+ int nproc = 0; 60+ int nproc = 0;
53+ 61+
54+ 62+
55+ /* get process number, stolen from ps */ 63+ /* get process number, stolen from ps */
56+ /* example with kvm functions */ 64+ /* example with kvm functions */
57+ char errbuf[_POSIX2_LINE_MAX]; 65+ char errbuf[_POSIX2_LINE_MAX];
58+ kvm_t *kdp = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, errbuf); 66+ kvm_t *kdp = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
59+ if (kdp == NULL) 67+ if (kdp == NULL)
60+ errx(1, "%s", errbuf); 68+ errx(1, "%s", errbuf);
61+ 69+
62+ /* fill kinfo_proc2 structure */ 70+ /* fill kinfo_proc2 structure */
63+ /* XXX does it return sleeping processes ? */ 71+ /* XXX does it return sleeping processes ? */
64+#ifdef __OpenBSD__ 72+#ifdef __OpenBSD__
65+ if (!(kp = kvm_getprocs(kdp, KERN_PROC_ALL, 0, 73+ if (!(kp = kvm_getprocs(kdp, KERN_PROC_ALL, 0,
66+ sizeof(struct kinfo_proc), &nproc))) 74+ sizeof(struct kinfo_proc), &nproc)))
67+#elif __DragonFly__ 75+#elif __DragonFly__
68+ if (!(kp = kvm_getprocs(kdp, KERN_PROC_ALL, 0, &nproc))) 76+ if (!(kp = kvm_getprocs(kdp, KERN_PROC_ALL, 0, &nproc)))
69+#else /* probably NetBSD or MirBSD */ 77+#else /* probably NetBSD or MirBSD */
70+ if (!(kp = kvm_getproc2(kdp, KERN_PROC_ALL, 0, 78+ if (!(kp = kvm_getproc2(kdp, KERN_PROC_ALL, 0,
71+ sizeof(struct kinfo_proc2), &nproc))) 79+ sizeof(struct kinfo_proc2), &nproc)))
72+#endif 80+#endif
73+ err(1, "%s", kvm_geterr(kdp)); 81+ err(1, "%s", kvm_geterr(kdp));
74+ 82+
75+ for (i = 0; i < nproc; i++) { 83+ for (i = 0; i < nproc; i++) {
76+ if (kp[i].p_pid < 1) 84+ if (kp[i].p_pid < 1)
77+ continue; /* not valid */ 85+ continue; /* not valid */
78  86
79- mib[0] = CTL_KERN; 87- mib[0] = CTL_KERN;
80-#ifdef __OpenBSD__ 88-#ifdef __OpenBSD__
81- mib[1] = KERN_PROC; 89- mib[1] = KERN_PROC;
82-#else 90-#else
83- mib[1] = KERN_PROC2; 91- mib[1] = KERN_PROC2;
84-#endif 92-#endif
85- mib[2] = KERN_PROC_ALL; 93- mib[2] = KERN_PROC_ALL;
86- mib[3] = 0; 94- mib[3] = 0;
87-#ifdef __OpenBSD__ 95-#ifdef __OpenBSD__
88- mib[4] = sizeof(struct kinfo_proc); 96- mib[4] = sizeof(struct kinfo_proc);
89-#else 97-#else
90- mib[4] = sizeof(struct kinfo_proc2); 98- mib[4] = sizeof(struct kinfo_proc2);
91-#endif 99-#endif
92- mib[5] = 0; 100- mib[5] = 0;
93- if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) 101- if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0)
94-#ifdef __OpenBSD__ 102-#ifdef __OpenBSD__
95- errx(1, "could not get kern.proc size"); 103- errx(1, "could not get kern.proc size");
96-#else 104-#else
97- errx(1, "could not get kern.proc2 size"); 105- errx(1, "could not get kern.proc2 size");
98-#endif 106-#endif
99- size = 5 * size / 4; /* extra slop */ 107- size = 5 * size / 4; /* extra slop */
100- if ((kp = malloc(size)) == NULL) 108- if ((kp = malloc(size)) == NULL)
101- errx(1,"failed to allocate memory for proc structures"); 109- errx(1,"failed to allocate memory for proc structures");
102-#ifdef __OpenBSD__ 110-#ifdef __OpenBSD__
103- mib[5] = (int)(size / sizeof(struct kinfo_proc)); 111- mib[5] = (int)(size / sizeof(struct kinfo_proc));
104-#else 112-#else
105- mib[5] = (int)(size / sizeof(struct kinfo_proc2)); 113- mib[5] = (int)(size / sizeof(struct kinfo_proc2));
106-#endif 114-#endif
107- if (sysctl(mib, 6, kp, &size, NULL, 0) < 0) 115- if (sysctl(mib, 6, kp, &size, NULL, 0) < 0)
108-#ifdef __OpenBSD__ 116-#ifdef __OpenBSD__
109- errx(1, "could not read kern.proc"); 117- errx(1, "could not read kern.proc");
110- nproc = (int)(size / sizeof(struct kinfo_proc)); 118- nproc = (int)(size / sizeof(struct kinfo_proc));
111-#else 119-#else
112- errx(1, "could not read kern.proc2"); 120- errx(1, "could not read kern.proc2");
113- nproc = (int)(size / sizeof(struct kinfo_proc2)); 121- nproc = (int)(size / sizeof(struct kinfo_proc2));
114-#endif 122-#endif
115- for (i=0 ; i < nproc ; i++) 123- for (i=0 ; i < nproc ; i++)
116- { 124- {
117-#ifdef __OpenBSD__ 125-#ifdef __OpenBSD__
118- struct kinfo_proc p = kp[i]; 126- struct kinfo_proc p = kp[i];
119-#else 127-#else
120+ /* get per-process information in our entry */ 128+ /* get per-process information in our entry */
121+#ifdef __NetBSD__ 129+#ifdef __NetBSD__
122 struct kinfo_proc2 p = kp[i]; 130 struct kinfo_proc2 p = kp[i];
123+#else 131+#else
124+ struct kinfo_proc p = kp[i]; 132+ struct kinfo_proc p = kp[i];
125 #endif 133 #endif
126- t.pid = p.p_pid; 134- t.pid = p.p_pid;
127- t.ppid = p.p_ppid; 135- t.ppid = p.p_ppid;
128- t.uid = p.p_uid; 136- t.uid = p.p_uid;
129- t.prio = p.p_priority - PZERO; 137- t.prio = p.p_priority - PZERO;
130- t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize; 138- t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize;
131- t.vsz *= getpagesize(); 139- t.vsz *= getpagesize();
132- t.rss = p.p_vm_rssize * getpagesize(); 140- t.rss = p.p_vm_rssize * getpagesize();
133- g_snprintf(t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]); 141- g_snprintf(t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]);
134- g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1); 142- g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1);
135- /* shamelessly stolen from top/machine.c */ 143- /* shamelessly stolen from top/machine.c */
136- if (!P_ZOMBIE(&p)) { 144- if (!P_ZOMBIE(&p)) {
137- size = 128; 145- size = 128;
138- if ((args = malloc(size)) == NULL) 146- if ((args = malloc(size)) == NULL)
139- errx(1,"failed to allocate memory for argv structures at %zu", size); 147- errx(1,"failed to allocate memory for argv structures at %zu", size);
140- for (;; size *= 2) { 148- for (;; size *= 2) {
141- if ((args = realloc(args, size)) == NULL) 149- if ((args = realloc(args, size)) == NULL)
142- errx(1,"failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid); 150- errx(1,"failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid);
143- mib[0] = CTL_KERN; 151- mib[0] = CTL_KERN;
144- mib[1] = KERN_PROC_ARGS; 152- mib[1] = KERN_PROC_ARGS;
145- mib[2] = t.pid; 153- mib[2] = t.pid;
146- mib[3] = KERN_PROC_ARGV; 154- mib[3] = KERN_PROC_ARGV;
147- if (sysctl(mib, 4, args, &size, NULL, 0) == 0) 155- if (sysctl(mib, 4, args, &size, NULL, 0) == 0)
148- break; 156- break;
149- if (errno != ENOMEM) { /* ESRCH: process disappeared */ 157- if (errno != ENOMEM) { /* ESRCH: process disappeared */
150- /* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */ 158- /* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */
151- args[0] ='\0'; 159- args[0] ='\0';
152- args[1] = NULL; 160- args[1] = NULL;
153- break; 161- break;
154- } 162- }
155- } 163- }
156- buf = g_strjoinv(" ", args); 164- buf = g_strjoinv(" ", args);
157- g_assert(g_utf8_validate(buf, -1, NULL)); 165- g_assert(g_utf8_validate(buf, -1, NULL));
158- g_strlcpy(t.cmdline, buf, sizeof t.cmdline); 166- g_strlcpy(t.cmdline, buf, sizeof t.cmdline);
159- g_free(buf); 167- g_free(buf);
160- free(args); 168- free(args);
161- } 169- }
162- 170-
163- t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE)); 171- t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE));
164- t.cpu_system = 0; /* TODO ? */ 172- t.cpu_system = 0; /* TODO ? */
165- /* get username from uid */ 173- /* get username from uid */
166- passwdp = getpwuid(t.uid); 174- passwdp = getpwuid(t.uid);
167- if(passwdp != NULL && passwdp->pw_name != NULL) 175- if(passwdp != NULL && passwdp->pw_name != NULL)
168- g_strlcpy(t.uid_name, passwdp->pw_name, sizeof t.uid_name); 176- g_strlcpy(t.uid_name, passwdp->pw_name, sizeof t.uid_name);
169- g_array_append_val(task_list, t); 177- g_array_append_val(task_list, t);
170- } 178- }
171- free(kp); 179- free(kp);
172+ 180+
173+#ifdef __DragonFly__ 181+#ifdef __DragonFly__
174+ t.pid = p.kp_pid; 182+ t.pid = p.kp_pid;
175+ t.ppid = p.kp_ppid; 183+ t.ppid = p.kp_ppid;
176+ t.uid = p.kp_uid; 184+ t.uid = p.kp_uid;
177+ t.prio = p.kp_nice; 185+ t.prio = p.kp_nice;
178+ t.vsz = p.kp_vm_dsize + p.kp_vm_ssize + p.kp_vm_tsize; 186+ t.vsz = p.kp_vm_dsize + p.kp_vm_ssize + p.kp_vm_tsize;
179+ t.vsz *= getpagesize(); 187+ t.vsz *= getpagesize();
180+ t.rss = p.kp_vm_rssize * getpagesize(); 188+ t.rss = p.kp_vm_rssize * getpagesize();
181+ g_snprintf(t.state, sizeof(t.state), "%s", 189+ g_snprintf(t.state, sizeof(t.state), "%s",
182+ state_abbrev[p.kp_stat]); 190+ state_abbrev[p.kp_stat]);
183+ g_strlcpy(t.name, p.kp_comm, strlen(p.kp_comm) + 1); 191+ g_strlcpy(t.name, p.kp_comm, strlen(p.kp_comm) + 1);
184+#else 192+#else
185+ t.pid = p.p_pid; 193+ t.pid = p.p_pid;
186+ t.ppid = p.p_ppid; 194+ t.ppid = p.p_ppid;
187+ t.uid = p.p_uid; 195+ t.uid = p.p_uid;
188+ t.prio = p.p_priority - PZERO; 196+ t.prio = p.p_priority - PZERO;
189+ t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize; 197+ t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize;
190+ t.vsz *= getpagesize(); 198+ t.vsz *= getpagesize();
191+ t.rss = p.p_vm_rssize * getpagesize(); 199+ t.rss = p.p_vm_rssize * getpagesize();
192+ g_snprintf(t.state, sizeof(t.state), "%s", 200+ g_snprintf(t.state, sizeof(t.state), "%s",
193+ state_abbrev[p.p_stat]); 201+ state_abbrev[p.p_stat]);
194+ g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1); 202+ g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1);
195+#endif 203+#endif
196+#ifdef __DragonFly__ 204+#ifdef __DragonFly__
197+ if (!(p.kp_stat == SDEAD)) { /* same as OpenBSD P_ZOMBIE */ 205+ if (!(p.kp_stat == SDEAD)) { /* same as OpenBSD P_ZOMBIE */
198+#else 206+#else
199+ if (!(p.p_stat == SDEAD)) { 207+ if (!(p.p_stat == SDEAD)) {
200+#endif 208+#endif
201+ /* get process args */ 209+ /* get process args */
202+#ifdef __NetBSD__ 210+#ifdef __NetBSD__
203+ args = kvm_getargv2(kdp, &kp[i], BUFSIZ); 211+ args = kvm_getargv2(kdp, &kp[i], BUFSIZ);
204+#else 212+#else
205+ args = kvm_getargv(kdp, &kp[i], BUFSIZ); 213+ args = kvm_getargv(kdp, &kp[i], BUFSIZ);
206+#endif 214+#endif
207+ if (args != NULL) { 215+ if (args != NULL) {
208+ buf = g_strjoinv(" ", args); 216+ buf = g_strjoinv(" ", args);
209+ g_strlcpy(t.cmdline, buf, 217+ g_strlcpy(t.cmdline, buf,
210+ sizeof(t.cmdline)); 218+ sizeof(t.cmdline));
211+ } 219+ }
212+#ifdef __DragonFly__ 220+#ifdef __DragonFly__
213+ t.cpu_user = 0; /* TODO */ 221+ t.cpu_user = 0; /* TODO */
214+#else 222+#else
215+ t.cpu_user = (100.0 * 223+ t.cpu_user = (100.0 *
216+ ((double) p.p_pctcpu / FSCALE)); 224+ ((double) p.p_pctcpu / FSCALE));
217+#endif 225+#endif
218+ t.cpu_system = 0; /* XXX TODO */ 226+ t.cpu_system = 0; /* XXX TODO */
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);
246 #endif 254 #endif
247  255
248 mib[0] = CTL_KERN; 256 mib[0] = CTL_KERN;
249-#ifdef __OpenBSD__ 257-#ifdef __OpenBSD__
250- mib[1] = KERN_PROC; 258- mib[1] = KERN_PROC;
251-#else 259-#else
252+#ifdef __NetBSD__ 260+#ifdef __NetBSD__
253 mib[1] = KERN_PROC2; 261 mib[1] = KERN_PROC2;
254+#else 262+#else
255+ mib[1] = KERN_PROC; 263+ mib[1] = KERN_PROC;
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)
295+ errx(1, "failed to sysctl kern.cputime"); 303+ errx(1, "failed to sysctl kern.cputime");
296+ 304+
297+ cp_time[CP_USER] = percpu.cp_user; 305+ cp_time[CP_USER] = percpu.cp_user;
298+ cp_time[CP_NICE] = percpu.cp_nice; 306+ cp_time[CP_NICE] = percpu.cp_nice;
299+ cp_time[CP_SYS] = percpu.cp_sys; 307+ cp_time[CP_SYS] = percpu.cp_sys;
300+ cp_time[CP_INTR] = percpu.cp_intr; 308+ cp_time[CP_INTR] = percpu.cp_intr;
301+ cp_time[CP_IDLE] = percpu.cp_idle; 309+ cp_time[CP_IDLE] = percpu.cp_idle;
302+#else 310+#else
303+#ifdef __NetBSD__ 311+#ifdef __NetBSD__
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};
331+ struct uvmexp uvmexp; 339+ struct uvmexp uvmexp;
332 #else 340 #else
333- int mib[] = {CTL_VM, VM_METER}; 341- int mib[] = {CTL_VM, VM_METER};
334- struct vmtotal vmtotal; 342- struct vmtotal vmtotal;
335+ int mib[] = {CTL_VM, VM_METER}; 343+ int mib[] = {CTL_VM, VM_METER};
336+ struct vmtotal vmtotal; 344+ struct vmtotal vmtotal;
337 #endif 345 #endif
338- struct swapent *swdev; 346- struct swapent *swdev;
339- int nswap, i; 347- int nswap, i;
340- size_t size; 348- size_t size;
341-#ifdef __OpenBSD__ 349-#ifdef __OpenBSD__
342- size = sizeof(uvmexp); 350- size = sizeof(uvmexp);
343- if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) 351- if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
344- errx(1,"failed to get vm.uvmexp"); 352- errx(1,"failed to get vm.uvmexp");
345- /* cheat : rm = tot used, add free to get total */ 353- /* cheat : rm = tot used, add free to get total */
346- *memory_free = pagetok((guint64)uvmexp.free); 354- *memory_free = pagetok((guint64)uvmexp.free);
347- *memory_total = pagetok((guint64)uvmexp.npages); 355- *memory_total = pagetok((guint64)uvmexp.npages);
348- *memory_cache = 0; 356- *memory_cache = 0;
349- *memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/ 357- *memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/
350-#else 358-#else
351- size = sizeof(vmtotal); 359- size = sizeof(vmtotal);
352- if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0) 360- if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0)
353- errx(1,"failed to get vm.meter"); 361- errx(1,"failed to get vm.meter");
354- /* cheat : rm = tot used, add free to get total */ 362- /* cheat : rm = tot used, add free to get total */
355- *memory_total = pagetok(vmtotal.t_rm + vmtotal.t_free); 363- *memory_total = pagetok(vmtotal.t_rm + vmtotal.t_free);
356- *memory_free = pagetok(vmtotal.t_free); 364- *memory_free = pagetok(vmtotal.t_free);
357- *memory_cache = 0; 365- *memory_cache = 0;
358- *memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm); 366- *memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm);
359-#endif 367-#endif
360- 368-
361- /* get swap stats */ 369- /* get swap stats */
362- if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0) 370- if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0)
363- errx(1,"failed to get swap device count"); 371- errx(1,"failed to get swap device count");
364- 372-
365- if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL) 373- if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL)
366- errx(1,"failed to allocate memory for swdev structures"); 374- errx(1,"failed to allocate memory for swdev structures");
367- 375-
368- if (swapctl(SWAP_STATS, swdev, nswap) == -1) { 376- if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
369- free(swdev); 377- free(swdev);
370- errx(1,"failed to get swap stats"); 378- errx(1,"failed to get swap stats");
371- } 379- }
372- 380-
373- /* Total things up */ 381- /* Total things up */
374- *swap_total = *swap_free = 0; 382- *swap_total = *swap_free = 0;
375- for (i = 0; i < nswap; i++) { 383- for (i = 0; i < nswap; i++) {
376- if (swdev[i].se_flags & SWF_ENABLE) { 384- if (swdev[i].se_flags & SWF_ENABLE) {
377- *swap_free += (swdev[i].se_nblks - swdev[i].se_inuse); 385- *swap_free += (swdev[i].se_nblks - swdev[i].se_inuse);
378- *swap_total += swdev[i].se_nblks; 386- *swap_total += swdev[i].se_nblks;
379- } 387- }
380- } 388- }
381- *swap_total *= DEV_BSIZE; 389- *swap_total *= DEV_BSIZE;
382- *swap_free *= DEV_BSIZE; 390- *swap_free *= DEV_BSIZE;
383- free(swdev); 391- free(swdev);
384- return TRUE; 392- return TRUE;
385+ struct swapent *swdev; 393+ struct swapent *swdev;
386+ int nswap, i; 394+ int nswap, i;
387+ size_t size; 395+ size_t size;
388+#ifdef __OpenBSD__ 396+#ifdef __OpenBSD__
389+ size = sizeof(uvmexp); 397+ size = sizeof(uvmexp);
390+ if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) 398+ if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
391+ errx(1,"failed to get vm.uvmexp"); 399+ errx(1,"failed to get vm.uvmexp");
392+ /* cheat : rm = tot used, add free to get total */ 400+ /* cheat : rm = tot used, add free to get total */
393+ *memory_free = pagetok((guint64)uvmexp.free); 401+ *memory_free = pagetok((guint64)uvmexp.free);
394+ *memory_total = pagetok((guint64)uvmexp.npages); 402+ *memory_total = pagetok((guint64)uvmexp.npages);
395+ *memory_cache = 0; 403+ *memory_cache = 0;
396+ *memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/ 404+ *memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/
397+#else 405+#else
398+ size = sizeof(vmtotal); 406+ size = sizeof(vmtotal);
399+ if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0) 407+ if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0)
400+ errx(1,"failed to get vm.meter"); 408+ errx(1,"failed to get vm.meter");
401+ 409+
402+ mib[0] = CTL_HW; 410+ mib[0] = CTL_HW;
403+ mib[1] = HW_PHYSMEM64; 411+ mib[1] = HW_PHYSMEM64;
404+ uint64_t physmem; 412+ uint64_t physmem;
405+ size_t physmemlen = sizeof(physmem); 413+ size_t physmemlen = sizeof(physmem);
406+ 414+
407+ if (sysctl(mib, 2, &physmem, &physmemlen, NULL, 0) < 0) 415+ if (sysctl(mib, 2, &physmem, &physmemlen, NULL, 0) < 0)
408+ errx(1, "failed to get physmem"); 416+ errx(1, "failed to get physmem");
409+ 417+
410+ *memory_total = (guint64)physmem; 418+ *memory_total = (guint64)physmem;
411+ *memory_free = pagetok((guint64)vmtotal.t_free); 419+ *memory_free = pagetok((guint64)vmtotal.t_free);
412+ *memory_cache = 0; 420+ *memory_cache = 0;
413+ *memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm); 421+ *memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm);
414+#endif 422+#endif
415+ 423+
416+ /* get swap stats */ 424+ /* get swap stats */
417+ if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0) 425+ if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0)
418+ errx(1,"failed to get swap device count"); 426+ errx(1,"failed to get swap device count");
419+ 427+
420+ if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL) 428+ if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL)
421+ errx(1,"failed to allocate memory for swdev structures"); 429+ errx(1,"failed to allocate memory for swdev structures");
422+ 430+
423+ if (swapctl(SWAP_STATS, swdev, nswap) == -1) { 431+ if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
424+ free(swdev); 432+ free(swdev);
425+ errx(1,"failed to get swap stats"); 433+ errx(1,"failed to get swap stats");
426+ } 434+ }
427+ 435+
428+ /* Total things up */ 436+ /* Total things up */
429+ *swap_total = *swap_free = 0; 437+ *swap_total = *swap_free = 0;
430+ for (i = 0; i < nswap; i++) { 438+ for (i = 0; i < nswap; i++) {
431+ if (swdev[i].se_flags & SWF_ENABLE) { 439+ if (swdev[i].se_flags & SWF_ENABLE) {
432+ *swap_free += (swdev[i].se_nblks - swdev[i].se_inuse); 440+ *swap_free += (swdev[i].se_nblks - swdev[i].se_inuse);
433+ *swap_total += swdev[i].se_nblks; 441+ *swap_total += swdev[i].se_nblks;
434+ } 442+ }
435+ } 443+ }
436+ *swap_total *= DEV_BSIZE; 444+ *swap_total *= DEV_BSIZE;
437+ *swap_free *= DEV_BSIZE; 445+ *swap_free *= DEV_BSIZE;
438+ free(swdev); 446+ free(swdev);
439+ return TRUE; 447+ return TRUE;
440 } 448 }
441  449