Lines 1-361
Link Here
|
1 |
--- src/resmom/freebsd/mom_mach.c.orig Tue Jun 20 02:23:04 2006 |
|
|
2 |
+++ src/resmom/freebsd/mom_mach.c Thu Sep 14 19:09:58 2006 |
3 |
@@ -370,40 +370,10 @@ |
4 |
continue; |
5 |
|
6 |
nps++; |
7 |
- cputime += tvk(pp->kp_proc.p_rtime); |
8 |
|
9 |
- if (pp->kp_proc.p_ru == NULL) { |
10 |
- struct pstats ps; |
11 |
- |
12 |
- DBPRT(("%s: p_stats 0x%lx\n", id, |
13 |
- (u_long)pp->kp_proc.p_stats)) |
14 |
- if (pp->kp_proc.p_stats == NULL) |
15 |
- continue; |
16 |
- |
17 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_stats, &ps, |
18 |
- sizeof(ps)) != sizeof(ps)) { |
19 |
- log_err(errno, id, "kvm_read(pstats)"); |
20 |
- continue; |
21 |
- } |
22 |
- cputime += tv(ps.p_ru.ru_utime) + |
23 |
- tv(ps.p_ru.ru_stime) + |
24 |
- tv(ps.p_cru.ru_utime) + |
25 |
- tv(ps.p_cru.ru_stime); |
26 |
- } |
27 |
- else { |
28 |
- struct rusage ru; |
29 |
- |
30 |
- DBPRT(("%s: p_ru 0x%lx\n", id, |
31 |
- (u_long)pp->kp_proc.p_ru)) |
32 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_ru, &ru, |
33 |
- sizeof(ru)) != sizeof(ru)) { |
34 |
- log_err(errno, id, "kvm_read(session)"); |
35 |
- continue; |
36 |
- } |
37 |
- cputime += tv(ru.ru_utime) + tv(ru.ru_stime); |
38 |
- } |
39 |
+ cputime += pp->ki_runtime / 1000000; |
40 |
DBPRT(("%s: ses %d pid %d cputime %d\n", id, |
41 |
- sess_tbl[i], pp->kp_proc.p_pid, cputime)) |
42 |
+ sess_tbl[i], pp->ki_pid, pp->ki_runtime / 1000000)) |
43 |
} |
44 |
|
45 |
if (nps == 0) |
46 |
@@ -434,11 +404,9 @@ |
47 |
if (!injob(pjob, sess_tbl[i])) |
48 |
continue; |
49 |
|
50 |
- memsize += ctob(pp->kp_eproc.e_vm.vm_tsize + |
51 |
- pp->kp_eproc.e_vm.vm_dsize + |
52 |
- pp->kp_eproc.e_vm.vm_ssize); |
53 |
+ memsize += pp->ki_size; |
54 |
DBPRT(("%s: ses %d pid=%d totmem=%lu\n", id, |
55 |
- sess_tbl[i], pp->kp_proc.p_pid, memsize)) |
56 |
+ sess_tbl[i], pp->ki_pid, pp->ki_size)) |
57 |
} |
58 |
|
59 |
return (memsize); |
60 |
@@ -461,10 +429,10 @@ |
61 |
if (!injob(pjob, sess_tbl[i])) |
62 |
continue; |
63 |
|
64 |
- memsize += ctob(pp->kp_eproc.e_vm.vm_rssize); |
65 |
+ memsize += pp->ki_rssize * PAGE_SIZE; |
66 |
DBPRT(("%s: pid=%d ses=%d mem=%d totmem=%d\n", id, |
67 |
- pp->kp_proc.p_pid, sess_tbl[i], |
68 |
- pp->kp_eproc.e_vm.vm_rssize, memsize)) |
69 |
+ pp->ki_pid, sess_tbl[i], |
70 |
+ pp->ki_rssize * PAGE_SIZE, memsize)) |
71 |
} |
72 |
|
73 |
return (memsize); |
74 |
@@ -485,9 +453,7 @@ |
75 |
if (!injob(pjob, sess_tbl[i])) |
76 |
continue; |
77 |
|
78 |
- if (ctob(pp->kp_eproc.e_vm.vm_tsize + |
79 |
- pp->kp_eproc.e_vm.vm_dsize + |
80 |
- pp->kp_eproc.e_vm.vm_ssize) > limit) |
81 |
+ if (pp->ki_size > limit) |
82 |
return (TRUE); |
83 |
} |
84 |
|
85 |
@@ -732,7 +698,7 @@ |
86 |
const void *b) |
87 |
|
88 |
{ |
89 |
- return((int)((struct kinfo_proc *)a)->kp_eproc.e_paddr - (int)((struct kinfo_proc *)b)->kp_eproc.e_paddr); |
90 |
+ return((int)((struct kinfo_proc *)a)->ki_paddr - (int)((struct kinfo_proc *)b)->ki_paddr); |
91 |
} |
92 |
|
93 |
int bs_cmp( |
94 |
@@ -741,7 +707,7 @@ |
95 |
const void *member) |
96 |
|
97 |
{ |
98 |
- return((int)((struct session *)key)->s_leader - (int)((struct kinfo_proc *)member)->kp_eproc.e_paddr); |
99 |
+ return((int)((struct session *)key)->s_leader - (int)((struct kinfo_proc *)member)->ki_paddr); |
100 |
} |
101 |
|
102 |
|
103 |
@@ -786,24 +752,10 @@ |
104 |
|
105 |
qsort(proc_tbl, nproc, sizeof(struct kinfo_proc), qs_cmp); |
106 |
|
107 |
- for (i=0, kp=proc_tbl; i<nproc; i++, kp++) { |
108 |
- if (kvm_read(kd, (u_long)kp->kp_eproc.e_sess, &ss, sizeof(ss)) |
109 |
- != sizeof(ss)) { |
110 |
- sprintf(log_buffer, |
111 |
- "kvm_read: %s", kvm_geterr(kd)); |
112 |
- log_err(errno, id, log_buffer); |
113 |
- return (PBSE_SYSTEM); |
114 |
- } |
115 |
- if (ss.s_leader == kp->kp_eproc.e_paddr || |
116 |
- ss.s_leader == NULL) { |
117 |
- sid = kp->kp_proc.p_pid; |
118 |
- } |
119 |
- else { |
120 |
- leader = bsearch(&ss, proc_tbl, nproc, |
121 |
- sizeof(struct kinfo_proc), bs_cmp); |
122 |
- sid = leader ? leader->kp_proc.p_pid : 0; |
123 |
- } |
124 |
- sess_tbl[i] = sid; |
125 |
+ for (i=0; i<nproc; i++) { |
126 |
+ struct kinfo_proc *pp = &proc_tbl[i]; |
127 |
+ |
128 |
+ sess_tbl[i] = pp->ki_sid; |
129 |
} |
130 |
|
131 |
return (PBSE_NONE); |
132 |
@@ -1012,8 +964,8 @@ |
133 |
continue; |
134 |
|
135 |
DBPRT(("%s: send signal %d to pid %d\n", id, |
136 |
- sig, pp->kp_proc.p_pid)) |
137 |
- (void)kill(pp->kp_proc.p_pid, sig); |
138 |
+ sig, pp->ki_pid)) |
139 |
+ (void)kill(pp->ki_pid, sig); |
140 |
++ct; |
141 |
} |
142 |
return ct; |
143 |
@@ -1118,36 +1070,10 @@ |
144 |
if (jobid != sess_tbl[i]) |
145 |
continue; |
146 |
|
147 |
- cputime += tvk(pp->kp_proc.p_rtime); |
148 |
- |
149 |
- if (pp->kp_proc.p_ru == NULL) { |
150 |
- struct pstats ps; |
151 |
- |
152 |
- if (pp->kp_proc.p_stats == NULL) |
153 |
- continue; |
154 |
- |
155 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_stats, &ps, |
156 |
- sizeof(ps)) != sizeof(ps)) { |
157 |
- log_err(errno, id, "kvm_read(pstats)"); |
158 |
- continue; |
159 |
- } |
160 |
- cputime += tv(ps.p_ru.ru_utime) + |
161 |
- tv(ps.p_ru.ru_stime) + |
162 |
- tv(ps.p_cru.ru_utime) + |
163 |
- tv(ps.p_cru.ru_stime); |
164 |
- } |
165 |
- else { |
166 |
- struct rusage ru; |
167 |
+ cputime += pp->ki_runtime / 1000000; |
168 |
|
169 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_ru, &ru, |
170 |
- sizeof(ru)) != sizeof(ru)) { |
171 |
- log_err(errno, id, "kvm_read(session)"); |
172 |
- continue; |
173 |
- } |
174 |
- cputime += tv(ru.ru_utime) + tv(ru.ru_stime); |
175 |
- } |
176 |
DBPRT(("%s: ses %d pid %d cputime %d\n", id, |
177 |
- jobid, pp->kp_proc.p_pid, cputime)) |
178 |
+ jobid, pp->ki_pid, cputime)) |
179 |
|
180 |
} |
181 |
|
182 |
@@ -1166,37 +1092,11 @@ |
183 |
for (i=0; i<nproc; i++) { |
184 |
struct kinfo_proc *pp = &proc_tbl[i]; |
185 |
|
186 |
- if (pid != pp->kp_proc.p_pid) |
187 |
+ if (pid != pp->ki_pid) |
188 |
continue; |
189 |
|
190 |
- cputime = tvk(pp->kp_proc.p_rtime); |
191 |
- |
192 |
- if (pp->kp_proc.p_ru == NULL) { |
193 |
- struct pstats ps; |
194 |
- |
195 |
- if (pp->kp_proc.p_stats == NULL) |
196 |
- break; |
197 |
- |
198 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_stats, &ps, |
199 |
- sizeof(ps)) != sizeof(ps)) { |
200 |
- log_err(errno, id, "kvm_read(pstats)"); |
201 |
- break; |
202 |
- } |
203 |
- cputime += tv(ps.p_ru.ru_utime) + |
204 |
- tv(ps.p_ru.ru_stime) + |
205 |
- tv(ps.p_cru.ru_utime) + |
206 |
- tv(ps.p_cru.ru_stime); |
207 |
- } |
208 |
- else { |
209 |
- struct rusage ru; |
210 |
+ cputime = pp->ki_runtime / 1000000; |
211 |
|
212 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_ru, &ru, |
213 |
- sizeof(ru)) != sizeof(ru)) { |
214 |
- log_err(errno, id, "kvm_read(session)"); |
215 |
- break; |
216 |
- } |
217 |
- cputime += tv(ru.ru_utime) + tv(ru.ru_stime); |
218 |
- } |
219 |
DBPRT(("%s: pid %d cputime %d\n", id, pid, cputime)) |
220 |
|
221 |
sprintf(ret_string, "%.2f", (double)cputime * cputfactor); |
222 |
@@ -1261,13 +1161,11 @@ |
223 |
continue; |
224 |
|
225 |
found = 1; |
226 |
- addmem = pp->kp_eproc.e_vm.vm_tsize + |
227 |
- pp->kp_eproc.e_vm.vm_dsize + |
228 |
- pp->kp_eproc.e_vm.vm_ssize; |
229 |
+ addmem = pp->ki_size; |
230 |
memsize += addmem; |
231 |
} |
232 |
if (found) { |
233 |
- sprintf(ret_string, "%ukb", ctob(memsize) >> 10); /* KB */ |
234 |
+ sprintf(ret_string, "%ukb", memsize / 1024); /* KB */ |
235 |
return ret_string; |
236 |
} |
237 |
|
238 |
@@ -1289,13 +1187,11 @@ |
239 |
for (i=0; i<nproc; i++) { |
240 |
struct kinfo_proc *pp = &proc_tbl[i]; |
241 |
|
242 |
- if (pid != pp->kp_proc.p_pid) |
243 |
+ if (pid != pp->ki_pid) |
244 |
continue; |
245 |
|
246 |
- memsize = pp->kp_eproc.e_vm.vm_tsize + |
247 |
- pp->kp_eproc.e_vm.vm_dsize + |
248 |
- pp->kp_eproc.e_vm.vm_ssize; |
249 |
- sprintf(ret_string, "%ukb", ctob(memsize) >> 10); /* KB */ |
250 |
+ memsize = pp->ki_size; |
251 |
+ sprintf(ret_string, "%ukb", memsize / 1024); /* KB */ |
252 |
return ret_string; |
253 |
} |
254 |
|
255 |
@@ -1358,10 +1254,10 @@ |
256 |
continue; |
257 |
|
258 |
found = 1; |
259 |
- resisize += pp->kp_eproc.e_vm.vm_rssize; |
260 |
+ resisize += pp->ki_rssize * PAGE_SIZE; |
261 |
} |
262 |
if (found) { |
263 |
- sprintf(ret_string, "%ukb", ctob(resisize) >> 10); /* KB */ |
264 |
+ sprintf(ret_string, "%ukb", resisize / 1024); /* KB */ |
265 |
return ret_string; |
266 |
} |
267 |
|
268 |
@@ -1385,11 +1281,11 @@ |
269 |
for (i=0; i<nproc; i++) { |
270 |
struct kinfo_proc *pp = &proc_tbl[i]; |
271 |
|
272 |
- if (pid != pp->kp_proc.p_pid) |
273 |
+ if (pid != pp->ki_pid) |
274 |
continue; |
275 |
|
276 |
- resisize = pp->kp_eproc.e_vm.vm_rssize; |
277 |
- sprintf(ret_string, "%ukb", ctob(resisize) >> 10); /* KB */ |
278 |
+ resisize = pp->ki_rssize * PAGE_SIZE; |
279 |
+ sprintf(ret_string, "%ukb", resisize / 1024); /* KB */ |
280 |
return ret_string; |
281 |
} |
282 |
|
283 |
@@ -1462,12 +1358,12 @@ |
284 |
for (i=0; i<nproc; i++) { |
285 |
struct kinfo_proc *pp = &proc_tbl[i]; |
286 |
|
287 |
- if (pp->kp_eproc.e_pcred.p_ruid == 0) |
288 |
+ if (pp->ki_ruid == 0) |
289 |
continue; |
290 |
|
291 |
jobid = sess_tbl[i]; |
292 |
DBPRT(("%s: pid %d sid %u\n", |
293 |
- id, (int)pp->kp_proc.p_pid, jobid)) |
294 |
+ id, (int)pp->ki_pid, jobid)) |
295 |
for (j=0; j<njids; j++) { |
296 |
if (jids[j] == jobid) |
297 |
break; |
298 |
@@ -1548,12 +1444,12 @@ |
299 |
struct kinfo_proc *pp = &proc_tbl[i]; |
300 |
|
301 |
DBPRT(("%s[%d]: pid %d sid %u\n", |
302 |
- id, num_pids, pp->kp_proc.p_pid, sess_tbl[i])) |
303 |
+ id, num_pids, pp->ki_pid, sess_tbl[i])) |
304 |
if (jobid != sess_tbl[i]) |
305 |
continue; |
306 |
|
307 |
checkret(&fmt, 100); |
308 |
- sprintf(fmt, " %d", pp->kp_proc.p_pid); |
309 |
+ sprintf(fmt, " %d", pp->ki_pid); |
310 |
fmt += strlen(fmt); |
311 |
num_pids++; |
312 |
} |
313 |
@@ -1591,11 +1487,11 @@ |
314 |
for (i=0; i<nproc; i++) { |
315 |
struct kinfo_proc *pp = &proc_tbl[i]; |
316 |
|
317 |
- if ((uid = pp->kp_eproc.e_pcred.p_ruid) == 0) |
318 |
+ if ((uid = pp->ki_ruid) == 0) |
319 |
continue; |
320 |
|
321 |
DBPRT(("%s: pid %d uid %u\n", |
322 |
- id, (int)pp->kp_proc.p_pid, uid)) |
323 |
+ id, (int)pp->ki_pid, uid)) |
324 |
for (j=0; j<nuids; j++) { |
325 |
if (uids[j] == uid) |
326 |
break; |
327 |
@@ -1884,23 +1780,12 @@ |
328 |
continue; |
329 |
} |
330 |
else { |
331 |
- if (value != pp->kp_proc.p_pid) |
332 |
+ if (value != pp->ki_pid) |
333 |
continue; |
334 |
} |
335 |
|
336 |
- if (pp->kp_proc.p_stats == NULL) { |
337 |
- rm_errno = RM_ERR_SYSTEM; |
338 |
- return NULL; |
339 |
- } |
340 |
- |
341 |
- if (kvm_read(kd, (u_long)pp->kp_proc.p_stats, &ps, |
342 |
- sizeof(ps)) != sizeof(ps)) { |
343 |
- log_err(errno, id, "kvm_read(pstats)"); |
344 |
- rm_errno = RM_ERR_SYSTEM; |
345 |
- return NULL; |
346 |
- } |
347 |
found = 1; |
348 |
- start = MIN(start, ps.p_start.tv_sec); |
349 |
+ start = MIN(start, pp->ki_start.tv_sec); |
350 |
} |
351 |
if (found) { |
352 |
sprintf(ret_string, "%ld", (long)((double)(now - start) * wallfactor)); |
353 |
@@ -2035,7 +1920,7 @@ |
354 |
dirdev = sb.st_dev; |
355 |
DBPRT(("dir has devnum %d\n", dirdev)) |
356 |
|
357 |
- if (setfsent() == NULL) { |
358 |
+ if (setfsent() == 0) { |
359 |
log_err(errno, id, "setfsent"); |
360 |
rm_errno = RM_ERR_SYSTEM; |
361 |
return NULL; |