blob: 833e0f6bdeed64fad223dba980a10618b4e0d79b [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <sys/resource.h>
36#ifdef LINUX
37#include <sys/times.h>
38#include <linux/kernel.h>
Wichert Akkermanc7926982000-04-10 22:22:31 +000039#include <sys/quota.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#endif /* LINUX */
41#ifdef SUNOS4
42#include <ufs/quota.h>
43#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000044#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <sys/times.h>
46#include <sys/time.h>
47#endif
48
49static struct xlat resources[] = {
50#ifdef RLIMIT_CPU
51 { RLIMIT_CPU, "RLIMIT_CPU" },
52#endif
53#ifdef RLIMIT_FSIZE
54 { RLIMIT_FSIZE, "RLIMIT_FSIZE" },
55#endif
56#ifdef RLIMIT_DATA
57 { RLIMIT_DATA, "RLIMIT_DATA" },
58#endif
59#ifdef RLIMIT_STACK
60 { RLIMIT_STACK, "RLIMIT_STACK" },
61#endif
62#ifdef RLIMIT_CORE
63 { RLIMIT_CORE, "RLIMIT_CORE" },
64#endif
65#ifdef RLIMIT_RSS
66 { RLIMIT_RSS, "RLIMIT_RSS" },
67#endif
Wichert Akkermanc7926982000-04-10 22:22:31 +000068#ifdef RLIMIT_NPROC
69 { RLIMIT_NPROC,"RLIMIT_NPROC" },
70#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#ifdef RLIMIT_NOFILE
72 { RLIMIT_NOFILE,"RLIMIT_NOFILE" },
73#endif
Wichert Akkermanc7926982000-04-10 22:22:31 +000074#ifdef RLIMIT_MEMLOCK
75 { RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK" },
76#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077#ifdef RLIMIT_VMEM
78 { RLIMIT_VMEM, "RLIMIT_VMEM" },
79#endif
80#ifdef RLIMIT_AS
81 { RLIMIT_AS, "RLIMIT_AS" },
82#endif
83 { 0, NULL },
84};
85
86static char *
87sprintrlim(lim)
88long lim;
89{
90 static char buf[32];
91
92 if (lim == RLIM_INFINITY)
93 sprintf(buf, "RLIM_INFINITY");
94 else if (lim > 1024 && lim%1024 == 0)
95 sprintf(buf, "%ld*1024", lim/1024);
96 else
97 sprintf(buf, "%ld", lim);
98 return buf;
99}
100
101int
102sys_getrlimit(tcp)
103struct tcb *tcp;
104{
105 struct rlimit rlim;
106
107 if (entering(tcp)) {
108 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
109 tprintf(", ");
110 }
111 else {
112 if (syserror(tcp) || !verbose(tcp))
113 tprintf("%#lx", tcp->u_arg[1]);
114 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
115 tprintf("{...}");
116 else {
117 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
118 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
119 }
120 }
121 return 0;
122}
123
124int
125sys_setrlimit(tcp)
126struct tcb *tcp;
127{
128 struct rlimit rlim;
129
130 if (entering(tcp)) {
131 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
132 tprintf(", ");
133 if (!verbose(tcp))
134 tprintf("%#lx", tcp->u_arg[1]);
135 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
136 tprintf("{...}");
137 else {
138 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
139 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
140 }
141 }
142 return 0;
143}
144
John Hughesbdf48f52001-03-06 15:08:09 +0000145#if _LFS64_LARGEFILE
146static char *
147sprintrlim64(lim)
148rlim64_t lim;
149{
150 static char buf[64];
151
152 if (lim == RLIM64_INFINITY)
153 sprintf(buf, "RLIM64_INFINITY");
154 else if (lim > 1024 && lim%1024 == 0)
155 sprintf(buf, "%lld*1024", lim/1024);
156 else
157 sprintf(buf, "%lld", lim);
158 return buf;
159}
160
161int
162sys_getrlimit64(tcp)
163struct tcb *tcp;
164{
165 struct rlimit64 rlim;
166
167 if (entering(tcp)) {
168 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
169 tprintf(", ");
170 }
171 else {
172 if (syserror(tcp) || !verbose(tcp))
173 tprintf("%#lx", tcp->u_arg[1]);
174 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
175 tprintf("{...}");
176 else {
177 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
178 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
179 }
180 }
181 return 0;
182}
183
184int
185sys_setrlimit64(tcp)
186struct tcb *tcp;
187{
188 struct rlimit64 rlim;
189
190 if (entering(tcp)) {
191 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
192 tprintf(", ");
193 if (!verbose(tcp))
194 tprintf("%#lx", tcp->u_arg[1]);
195 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
196 tprintf("{...}");
197 else {
198 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
199 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
200 }
201 }
202 return 0;
203}
204#endif
205
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000206#ifndef SVR4
207
208static struct xlat usagewho[] = {
209 { RUSAGE_SELF, "RUSAGE_SELF" },
210 { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" },
Wichert Akkermanc7926982000-04-10 22:22:31 +0000211#ifdef RUSAGE_BOTH
212 { RUSAGE_BOTH, "RUSAGE_BOTH" },
213#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000214 { 0, NULL },
215};
216
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000217#ifdef ALPHA
218void
219printrusage32(tcp, addr)
220struct tcb *tcp;
221long addr;
222{
223 struct timeval32
224 {
225 unsigned tv_sec;
226 unsigned tv_usec;
227 };
228 struct rusage32
229 {
230 struct timeval32 ru_utime; /* user time used */
231 struct timeval32 ru_stime; /* system time used */
232 long ru_maxrss; /* maximum resident set size */
233 long ru_ixrss; /* integral shared memory size */
234 long ru_idrss; /* integral unshared data size */
235 long ru_isrss; /* integral unshared stack size */
236 long ru_minflt; /* page reclaims */
237 long ru_majflt; /* page faults */
238 long ru_nswap; /* swaps */
239 long ru_inblock; /* block input operations */
240 long ru_oublock; /* block output operations */
241 long ru_msgsnd; /* messages sent */
242 long ru_msgrcv; /* messages received */
243 long ru_nsignals; /* signals received */
244 long ru_nvcsw; /* voluntary context switches */
245 long ru_nivcsw; /* involuntary " */
246 } ru;
247
248 if (!addr)
249 tprintf("NULL");
250 else if (syserror(tcp) || !verbose(tcp))
251 tprintf("%#lx", addr);
252 else if (umove(tcp, addr, &ru) < 0)
253 tprintf("{...}");
254 else if (!abbrev(tcp)) {
255 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
256 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
257 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
258 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
259 ru.ru_maxrss, ru.ru_ixrss);
260 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
261 ru.ru_idrss, ru.ru_isrss);
262 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
263 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
264 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
265 ru.ru_inblock, ru.ru_oublock);
266 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
267 ru.ru_msgsnd, ru.ru_msgrcv);
268 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
269 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
270 }
271 else {
272 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
273 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
274 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
275 }
276}
277#endif
278
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279void
280printrusage(tcp, addr)
281struct tcb *tcp;
282long addr;
283{
284 struct rusage ru;
285
286 if (!addr)
287 tprintf("NULL");
288 else if (syserror(tcp) || !verbose(tcp))
289 tprintf("%#lx", addr);
290 else if (umove(tcp, addr, &ru) < 0)
291 tprintf("{...}");
292 else if (!abbrev(tcp)) {
293 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
294 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
295 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
296 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
297 ru.ru_maxrss, ru.ru_ixrss);
298 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
299 ru.ru_idrss, ru.ru_isrss);
300 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
301 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
302 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
303 ru.ru_inblock, ru.ru_oublock);
304 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
305 ru.ru_msgsnd, ru.ru_msgrcv);
306 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
307 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
308 }
309 else {
310 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
311 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
312 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
313 }
314}
315
316int
317sys_getrusage(tcp)
318struct tcb *tcp;
319{
320 if (entering(tcp)) {
321 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
322 tprintf(", ");
323 }
324 else
325 printrusage(tcp, tcp->u_arg[1]);
326 return 0;
327}
328
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000329#ifdef ALPHA
330int
331sys_osf_getrusage(tcp)
332struct tcb *tcp;
333{
334 if (entering(tcp)) {
335 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
336 tprintf(", ");
337 }
338 else
339 printrusage32(tcp, tcp->u_arg[1]);
340 return 0;
341}
342#endif /* ALPHA */
343
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344#endif /* !SVR4 */
345
346#ifdef LINUX
347
348int
349sys_sysinfo(tcp)
350struct tcb *tcp;
351{
352 struct sysinfo si;
353
354 if (exiting(tcp)) {
355 if (syserror(tcp) || !verbose(tcp))
356 tprintf("%#lx", tcp->u_arg[0]);
357 else if (umove(tcp, tcp->u_arg[0], &si) < 0)
358 tprintf("{...}");
359 else {
360 tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ",
361 si.uptime, si.loads[0], si.loads[1],
362 si.loads[2]);
363 tprintf("totalram=%lu, freeram=%lu, ",
364 si.totalram, si.freeram);
365 tprintf("sharedram=%lu, bufferram=%lu} ",
366 si.sharedram, si.bufferram);
367 tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}",
368 si.totalswap, si.freeswap, si.procs);
369 }
370 }
371 return 0;
372}
373
374#endif /* LINUX */
375
376static struct xlat priorities[] = {
377 { PRIO_PROCESS, "PRIO_PROCESS" },
378 { PRIO_PGRP, "PRIO_PGRP" },
379 { PRIO_USER, "PRIO_USER" },
380 { 0, NULL },
381};
382
383int
384sys_getpriority(tcp)
385struct tcb *tcp;
386{
387 if (entering(tcp)) {
388 printxval(priorities, tcp->u_arg[0], "PRIO_???");
389 tprintf(", %lu", tcp->u_arg[1]);
390 }
391 return 0;
392}
393
394int
395sys_setpriority(tcp)
396struct tcb *tcp;
397{
398 if (entering(tcp)) {
399 printxval(priorities, tcp->u_arg[0], "PRIO_???");
400 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
401 }
402 return 0;
403}
404
405int
406sys_nice(tcp)
407struct tcb *tcp;
408{
409 if (entering(tcp))
410 tprintf("%ld", tcp->u_arg[0]);
411 return 0;
412}
413
414#ifndef SUNOS4
415
416int
417sys_times(tcp)
418struct tcb *tcp;
419{
420 struct tms tbuf;
421
422 if (exiting(tcp)) {
423 if (tcp->u_arg[0] == 0)
424 tprintf("NULL");
425 else if (syserror(tcp))
426 tprintf("%#lx", tcp->u_arg[0]);
427 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
428 tprintf("{...}");
429 else {
430 tprintf("{tms_utime=%lu, tms_stime=%lu, ",
431 tbuf.tms_utime, tbuf.tms_stime);
432 tprintf("tms_cutime=%lu, tms_cstime=%lu}",
433 tbuf.tms_cutime, tbuf.tms_cstime);
434 }
435 }
436 return 0;
437}
438
439#endif /* !SUNOS4 */
440
Wichert Akkermanc7926982000-04-10 22:22:31 +0000441#ifdef LINUX
442
443static struct xlat quotacmds[] = {
444 { Q_QUOTAON, "Q_QUOTAON" },
445 { Q_QUOTAOFF, "Q_QUOTAOFF" },
446 { Q_GETQUOTA, "Q_GETQUOTA" },
447 { Q_SETQUOTA, "Q_SETQUOTA" },
448 { Q_SETUSE, "Q_SETUSE" },
449 { Q_SYNC, "Q_SYNC" },
450 { Q_SETQLIM, "Q_SETQLIM" },
451 { Q_GETSTATS, "Q_GETSTATS" },
452 { Q_RSQUASH, "Q_RSQUASH" },
453 { 0, NULL },
454};
455
456static struct xlat quotatypes[] = {
457 { USRQUOTA, "USRQUOTA" },
458 { GRPQUOTA, "GRPQUOTA" },
459 { 0, NULL },
460};
461
462int
463sys_quotactl(tcp)
464struct tcb *tcp;
465{
466 if (entering(tcp)) {
467 printxval(quotacmds, tcp->u_arg[0] >> SUBCMDSHIFT, "Q_???");
468 tprintf("|");
469 printxval(quotatypes, tcp->u_arg[0] & SUBCMDMASK, "???QUOTA");
470 tprintf(", ");
471 printstr(tcp, tcp->u_arg[1], -1);
472 tprintf(", %lu, ", tcp->u_arg[2]);
473 }
474 else {
475 struct dqblk dq;
476
477 if (!tcp->u_arg[3])
478 tprintf("NULL");
479 else if (!verbose(tcp))
480 tprintf("%#lx", tcp->u_arg[3]);
481 else if (umoven(tcp, tcp->u_arg[3], sizeof(struct dqblk),
482 (char *) &dq) < 0)
483 tprintf("???");
484 else {
485 tprintf("{");
486 tprintf("%u, ", dq.dqb_bhardlimit);
487 tprintf("%u, ", dq.dqb_bsoftlimit);
488 tprintf("%u, ", dq.dqb_curblocks);
489 tprintf("%u, ", dq.dqb_ihardlimit);
490 tprintf("%u, ", dq.dqb_isoftlimit);
491 tprintf("%u, ", dq.dqb_curinodes);
492 tprintf("%lu, ", dq.dqb_btime);
493 tprintf("%lu", dq.dqb_itime);
494 tprintf("}");
495 }
496
497 }
498 return 0;
499}
500
501#endif /* Linux */
502
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000503#if defined(SUNOS4) || defined(FREEBSD)
504
505#ifdef FREEBSD
506#include <ufs/ufs/quota.h>
507#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508
509static struct xlat quotacmds[] = {
510 { Q_QUOTAON, "Q_QUOTAON" },
511 { Q_QUOTAOFF, "Q_QUOTAOFF" },
512 { Q_GETQUOTA, "Q_GETQUOTA" },
513 { Q_SETQUOTA, "Q_SETQUOTA" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000514#ifdef Q_SETQLIM
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 { Q_SETQLIM, "Q_SETQLIM" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000516#endif
517#ifdef Q_SETUSE
518 { Q_SETUSE, "Q_SETUSE" },
519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 { Q_SYNC, "Q_SYNC" },
521 { 0, NULL },
522};
523
524int
525sys_quotactl(tcp)
526struct tcb *tcp;
527{
528 /* fourth arg (addr) not interpreted here */
529 if (entering(tcp)) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000530#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 printxval(quotacmds, tcp->u_arg[0], "Q_???");
532 tprintf(", ");
533 printstr(tcp, tcp->u_arg[1], -1);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000534#endif
535#ifdef FREEBSD
536 printpath(tcp, tcp->u_arg[0]);
537 tprintf(", ");
538 printxval(quotacmds, tcp->u_arg[1], "Q_???");
539#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 tprintf(", %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
541 }
542 return 0;
543}
544
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000545#endif /* SUNOS4 || FREEBSD */