blob: bb93fb63c83d2355ff73d27bf1ba626195f7138f [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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <sys/resource.h>
35#ifdef LINUX
36#include <sys/times.h>
37#include <linux/kernel.h>
38#endif /* LINUX */
39#ifdef SUNOS4
40#include <ufs/quota.h>
41#endif /* SUNOS4 */
42#ifdef SVR4
43#include <sys/times.h>
44#include <sys/time.h>
45#endif
46
47static struct xlat resources[] = {
48#ifdef RLIMIT_CPU
49 { RLIMIT_CPU, "RLIMIT_CPU" },
50#endif
51#ifdef RLIMIT_FSIZE
52 { RLIMIT_FSIZE, "RLIMIT_FSIZE" },
53#endif
54#ifdef RLIMIT_DATA
55 { RLIMIT_DATA, "RLIMIT_DATA" },
56#endif
57#ifdef RLIMIT_STACK
58 { RLIMIT_STACK, "RLIMIT_STACK" },
59#endif
60#ifdef RLIMIT_CORE
61 { RLIMIT_CORE, "RLIMIT_CORE" },
62#endif
63#ifdef RLIMIT_RSS
64 { RLIMIT_RSS, "RLIMIT_RSS" },
65#endif
66#ifdef RLIMIT_NOFILE
67 { RLIMIT_NOFILE,"RLIMIT_NOFILE" },
68#endif
69#ifdef RLIMIT_VMEM
70 { RLIMIT_VMEM, "RLIMIT_VMEM" },
71#endif
72#ifdef RLIMIT_AS
73 { RLIMIT_AS, "RLIMIT_AS" },
74#endif
75 { 0, NULL },
76};
77
78static char *
79sprintrlim(lim)
80long lim;
81{
82 static char buf[32];
83
84 if (lim == RLIM_INFINITY)
85 sprintf(buf, "RLIM_INFINITY");
86 else if (lim > 1024 && lim%1024 == 0)
87 sprintf(buf, "%ld*1024", lim/1024);
88 else
89 sprintf(buf, "%ld", lim);
90 return buf;
91}
92
93int
94sys_getrlimit(tcp)
95struct tcb *tcp;
96{
97 struct rlimit rlim;
98
99 if (entering(tcp)) {
100 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
101 tprintf(", ");
102 }
103 else {
104 if (syserror(tcp) || !verbose(tcp))
105 tprintf("%#lx", tcp->u_arg[1]);
106 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
107 tprintf("{...}");
108 else {
109 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
110 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
111 }
112 }
113 return 0;
114}
115
116int
117sys_setrlimit(tcp)
118struct tcb *tcp;
119{
120 struct rlimit rlim;
121
122 if (entering(tcp)) {
123 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
124 tprintf(", ");
125 if (!verbose(tcp))
126 tprintf("%#lx", tcp->u_arg[1]);
127 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
128 tprintf("{...}");
129 else {
130 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
131 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
132 }
133 }
134 return 0;
135}
136
137#ifndef SVR4
138
139static struct xlat usagewho[] = {
140 { RUSAGE_SELF, "RUSAGE_SELF" },
141 { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" },
142 { 0, NULL },
143};
144
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000145#ifdef ALPHA
146void
147printrusage32(tcp, addr)
148struct tcb *tcp;
149long addr;
150{
151 struct timeval32
152 {
153 unsigned tv_sec;
154 unsigned tv_usec;
155 };
156 struct rusage32
157 {
158 struct timeval32 ru_utime; /* user time used */
159 struct timeval32 ru_stime; /* system time used */
160 long ru_maxrss; /* maximum resident set size */
161 long ru_ixrss; /* integral shared memory size */
162 long ru_idrss; /* integral unshared data size */
163 long ru_isrss; /* integral unshared stack size */
164 long ru_minflt; /* page reclaims */
165 long ru_majflt; /* page faults */
166 long ru_nswap; /* swaps */
167 long ru_inblock; /* block input operations */
168 long ru_oublock; /* block output operations */
169 long ru_msgsnd; /* messages sent */
170 long ru_msgrcv; /* messages received */
171 long ru_nsignals; /* signals received */
172 long ru_nvcsw; /* voluntary context switches */
173 long ru_nivcsw; /* involuntary " */
174 } ru;
175
176 if (!addr)
177 tprintf("NULL");
178 else if (syserror(tcp) || !verbose(tcp))
179 tprintf("%#lx", addr);
180 else if (umove(tcp, addr, &ru) < 0)
181 tprintf("{...}");
182 else if (!abbrev(tcp)) {
183 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
184 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
185 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
186 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
187 ru.ru_maxrss, ru.ru_ixrss);
188 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
189 ru.ru_idrss, ru.ru_isrss);
190 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
191 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
192 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
193 ru.ru_inblock, ru.ru_oublock);
194 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
195 ru.ru_msgsnd, ru.ru_msgrcv);
196 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
197 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
198 }
199 else {
200 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
201 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
202 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
203 }
204}
205#endif
206
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207void
208printrusage(tcp, addr)
209struct tcb *tcp;
210long addr;
211{
212 struct rusage ru;
213
214 if (!addr)
215 tprintf("NULL");
216 else if (syserror(tcp) || !verbose(tcp))
217 tprintf("%#lx", addr);
218 else if (umove(tcp, addr, &ru) < 0)
219 tprintf("{...}");
220 else if (!abbrev(tcp)) {
221 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
222 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
223 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
224 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
225 ru.ru_maxrss, ru.ru_ixrss);
226 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
227 ru.ru_idrss, ru.ru_isrss);
228 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
229 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
230 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
231 ru.ru_inblock, ru.ru_oublock);
232 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
233 ru.ru_msgsnd, ru.ru_msgrcv);
234 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
235 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
236 }
237 else {
238 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
239 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
240 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
241 }
242}
243
244int
245sys_getrusage(tcp)
246struct tcb *tcp;
247{
248 if (entering(tcp)) {
249 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
250 tprintf(", ");
251 }
252 else
253 printrusage(tcp, tcp->u_arg[1]);
254 return 0;
255}
256
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000257#ifdef ALPHA
258int
259sys_osf_getrusage(tcp)
260struct tcb *tcp;
261{
262 if (entering(tcp)) {
263 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
264 tprintf(", ");
265 }
266 else
267 printrusage32(tcp, tcp->u_arg[1]);
268 return 0;
269}
270#endif /* ALPHA */
271
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272#endif /* !SVR4 */
273
274#ifdef LINUX
275
276int
277sys_sysinfo(tcp)
278struct tcb *tcp;
279{
280 struct sysinfo si;
281
282 if (exiting(tcp)) {
283 if (syserror(tcp) || !verbose(tcp))
284 tprintf("%#lx", tcp->u_arg[0]);
285 else if (umove(tcp, tcp->u_arg[0], &si) < 0)
286 tprintf("{...}");
287 else {
288 tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ",
289 si.uptime, si.loads[0], si.loads[1],
290 si.loads[2]);
291 tprintf("totalram=%lu, freeram=%lu, ",
292 si.totalram, si.freeram);
293 tprintf("sharedram=%lu, bufferram=%lu} ",
294 si.sharedram, si.bufferram);
295 tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}",
296 si.totalswap, si.freeswap, si.procs);
297 }
298 }
299 return 0;
300}
301
302#endif /* LINUX */
303
304static struct xlat priorities[] = {
305 { PRIO_PROCESS, "PRIO_PROCESS" },
306 { PRIO_PGRP, "PRIO_PGRP" },
307 { PRIO_USER, "PRIO_USER" },
308 { 0, NULL },
309};
310
311int
312sys_getpriority(tcp)
313struct tcb *tcp;
314{
315 if (entering(tcp)) {
316 printxval(priorities, tcp->u_arg[0], "PRIO_???");
317 tprintf(", %lu", tcp->u_arg[1]);
318 }
319 return 0;
320}
321
322int
323sys_setpriority(tcp)
324struct tcb *tcp;
325{
326 if (entering(tcp)) {
327 printxval(priorities, tcp->u_arg[0], "PRIO_???");
328 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
329 }
330 return 0;
331}
332
333int
334sys_nice(tcp)
335struct tcb *tcp;
336{
337 if (entering(tcp))
338 tprintf("%ld", tcp->u_arg[0]);
339 return 0;
340}
341
342#ifndef SUNOS4
343
344int
345sys_times(tcp)
346struct tcb *tcp;
347{
348 struct tms tbuf;
349
350 if (exiting(tcp)) {
351 if (tcp->u_arg[0] == 0)
352 tprintf("NULL");
353 else if (syserror(tcp))
354 tprintf("%#lx", tcp->u_arg[0]);
355 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
356 tprintf("{...}");
357 else {
358 tprintf("{tms_utime=%lu, tms_stime=%lu, ",
359 tbuf.tms_utime, tbuf.tms_stime);
360 tprintf("tms_cutime=%lu, tms_cstime=%lu}",
361 tbuf.tms_cutime, tbuf.tms_cstime);
362 }
363 }
364 return 0;
365}
366
367#endif /* !SUNOS4 */
368
369#ifdef SUNOS4
370
371static struct xlat quotacmds[] = {
372 { Q_QUOTAON, "Q_QUOTAON" },
373 { Q_QUOTAOFF, "Q_QUOTAOFF" },
374 { Q_GETQUOTA, "Q_GETQUOTA" },
375 { Q_SETQUOTA, "Q_SETQUOTA" },
376 { Q_SETQLIM, "Q_SETQLIM" },
377 { Q_SYNC, "Q_SYNC" },
378 { 0, NULL },
379};
380
381int
382sys_quotactl(tcp)
383struct tcb *tcp;
384{
385 /* fourth arg (addr) not interpreted here */
386 if (entering(tcp)) {
387 printxval(quotacmds, tcp->u_arg[0], "Q_???");
388 tprintf(", ");
389 printstr(tcp, tcp->u_arg[1], -1);
390 tprintf(", %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
391 }
392 return 0;
393}
394
395#endif /* SUNOS4 */