Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 47 | static 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 | |
| 78 | static char * |
| 79 | sprintrlim(lim) |
| 80 | long 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 | |
| 93 | int |
| 94 | sys_getrlimit(tcp) |
| 95 | struct 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 | |
| 116 | int |
| 117 | sys_setrlimit(tcp) |
| 118 | struct 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 | |
| 139 | static struct xlat usagewho[] = { |
| 140 | { RUSAGE_SELF, "RUSAGE_SELF" }, |
| 141 | { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" }, |
| 142 | { 0, NULL }, |
| 143 | }; |
| 144 | |
| 145 | void |
| 146 | printrusage(tcp, addr) |
| 147 | struct tcb *tcp; |
| 148 | long addr; |
| 149 | { |
| 150 | struct rusage ru; |
| 151 | |
| 152 | if (!addr) |
| 153 | tprintf("NULL"); |
| 154 | else if (syserror(tcp) || !verbose(tcp)) |
| 155 | tprintf("%#lx", addr); |
| 156 | else if (umove(tcp, addr, &ru) < 0) |
| 157 | tprintf("{...}"); |
| 158 | else if (!abbrev(tcp)) { |
| 159 | tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ", |
| 160 | (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, |
| 161 | (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); |
| 162 | tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ", |
| 163 | ru.ru_maxrss, ru.ru_ixrss); |
| 164 | tprintf("ru_idrss=%lu, ru_isrss=%lu, ", |
| 165 | ru.ru_idrss, ru.ru_isrss); |
| 166 | tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ", |
| 167 | ru.ru_minflt, ru.ru_majflt, ru.ru_nswap); |
| 168 | tprintf("ru_inblock=%lu, ru_oublock=%lu, ", |
| 169 | ru.ru_inblock, ru.ru_oublock); |
| 170 | tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ", |
| 171 | ru.ru_msgsnd, ru.ru_msgrcv); |
| 172 | tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}", |
| 173 | ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw); |
| 174 | } |
| 175 | else { |
| 176 | tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}", |
| 177 | (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, |
| 178 | (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | int |
| 183 | sys_getrusage(tcp) |
| 184 | struct tcb *tcp; |
| 185 | { |
| 186 | if (entering(tcp)) { |
| 187 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
| 188 | tprintf(", "); |
| 189 | } |
| 190 | else |
| 191 | printrusage(tcp, tcp->u_arg[1]); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | #endif /* !SVR4 */ |
| 196 | |
| 197 | #ifdef LINUX |
| 198 | |
| 199 | int |
| 200 | sys_sysinfo(tcp) |
| 201 | struct tcb *tcp; |
| 202 | { |
| 203 | struct sysinfo si; |
| 204 | |
| 205 | if (exiting(tcp)) { |
| 206 | if (syserror(tcp) || !verbose(tcp)) |
| 207 | tprintf("%#lx", tcp->u_arg[0]); |
| 208 | else if (umove(tcp, tcp->u_arg[0], &si) < 0) |
| 209 | tprintf("{...}"); |
| 210 | else { |
| 211 | tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ", |
| 212 | si.uptime, si.loads[0], si.loads[1], |
| 213 | si.loads[2]); |
| 214 | tprintf("totalram=%lu, freeram=%lu, ", |
| 215 | si.totalram, si.freeram); |
| 216 | tprintf("sharedram=%lu, bufferram=%lu} ", |
| 217 | si.sharedram, si.bufferram); |
| 218 | tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}", |
| 219 | si.totalswap, si.freeswap, si.procs); |
| 220 | } |
| 221 | } |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | #endif /* LINUX */ |
| 226 | |
| 227 | static struct xlat priorities[] = { |
| 228 | { PRIO_PROCESS, "PRIO_PROCESS" }, |
| 229 | { PRIO_PGRP, "PRIO_PGRP" }, |
| 230 | { PRIO_USER, "PRIO_USER" }, |
| 231 | { 0, NULL }, |
| 232 | }; |
| 233 | |
| 234 | int |
| 235 | sys_getpriority(tcp) |
| 236 | struct tcb *tcp; |
| 237 | { |
| 238 | if (entering(tcp)) { |
| 239 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
| 240 | tprintf(", %lu", tcp->u_arg[1]); |
| 241 | } |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | int |
| 246 | sys_setpriority(tcp) |
| 247 | struct tcb *tcp; |
| 248 | { |
| 249 | if (entering(tcp)) { |
| 250 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
| 251 | tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]); |
| 252 | } |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | int |
| 257 | sys_nice(tcp) |
| 258 | struct tcb *tcp; |
| 259 | { |
| 260 | if (entering(tcp)) |
| 261 | tprintf("%ld", tcp->u_arg[0]); |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | #ifndef SUNOS4 |
| 266 | |
| 267 | int |
| 268 | sys_times(tcp) |
| 269 | struct tcb *tcp; |
| 270 | { |
| 271 | struct tms tbuf; |
| 272 | |
| 273 | if (exiting(tcp)) { |
| 274 | if (tcp->u_arg[0] == 0) |
| 275 | tprintf("NULL"); |
| 276 | else if (syserror(tcp)) |
| 277 | tprintf("%#lx", tcp->u_arg[0]); |
| 278 | else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0) |
| 279 | tprintf("{...}"); |
| 280 | else { |
| 281 | tprintf("{tms_utime=%lu, tms_stime=%lu, ", |
| 282 | tbuf.tms_utime, tbuf.tms_stime); |
| 283 | tprintf("tms_cutime=%lu, tms_cstime=%lu}", |
| 284 | tbuf.tms_cutime, tbuf.tms_cstime); |
| 285 | } |
| 286 | } |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | #endif /* !SUNOS4 */ |
| 291 | |
| 292 | #ifdef SUNOS4 |
| 293 | |
| 294 | static struct xlat quotacmds[] = { |
| 295 | { Q_QUOTAON, "Q_QUOTAON" }, |
| 296 | { Q_QUOTAOFF, "Q_QUOTAOFF" }, |
| 297 | { Q_GETQUOTA, "Q_GETQUOTA" }, |
| 298 | { Q_SETQUOTA, "Q_SETQUOTA" }, |
| 299 | { Q_SETQLIM, "Q_SETQLIM" }, |
| 300 | { Q_SYNC, "Q_SYNC" }, |
| 301 | { 0, NULL }, |
| 302 | }; |
| 303 | |
| 304 | int |
| 305 | sys_quotactl(tcp) |
| 306 | struct tcb *tcp; |
| 307 | { |
| 308 | /* fourth arg (addr) not interpreted here */ |
| 309 | if (entering(tcp)) { |
| 310 | printxval(quotacmds, tcp->u_arg[0], "Q_???"); |
| 311 | tprintf(", "); |
| 312 | printstr(tcp, tcp->u_arg[1], -1); |
| 313 | tprintf(", %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]); |
| 314 | } |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | #endif /* SUNOS4 */ |