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 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
38 static struct xlat fcntlcmds[] = {
39 { F_DUPFD, "F_DUPFD" },
40 { F_GETFD, "F_GETFD" },
41 { F_SETFD, "F_SETFD" },
42 { F_GETFL, "F_GETFL" },
43 { F_SETFL, "F_SETFL" },
44 { F_GETLK, "F_GETLK" },
45 { F_SETLK, "F_SETLK" },
46 { F_SETLKW, "F_SETLKW" },
47 { F_GETOWN, "F_GETOWN" },
48 { F_SETOWN, "F_SETOWN" },
50 { F_RSETLK, "F_RSETLK" },
53 { F_RSETLKW, "F_RSETLKW" },
56 { F_RGETLK, "F_RGETLK" },
62 { F_SETSIG, "F_SETSIG" },
65 { F_GETSIG, "F_GETSIG" },
70 static struct xlat fdflags[] = {
72 { FD_CLOEXEC, "FD_CLOEXEC" },
79 static struct xlat flockcmds[] = {
80 { LOCK_SH, "LOCK_SH" },
81 { LOCK_EX, "LOCK_EX" },
82 { LOCK_NB, "LOCK_NB" },
83 { LOCK_UN, "LOCK_UN" },
89 static struct xlat lockfcmds[] = {
90 { F_RDLCK, "F_RDLCK" },
91 { F_WRLCK, "F_WRLCK" },
92 { F_UNLCK, "F_UNLCK" },
94 { F_EXLCK, "F_EXLCK" },
97 { F_SHLCK, "F_SHLCK" },
102 static struct xlat whence[] = {
103 { SEEK_SET, "SEEK_SET" },
104 { SEEK_CUR, "SEEK_CUR" },
105 { SEEK_END, "SEEK_END" },
111 printflock(tcp, addr, getlk)
118 if (umove(tcp, addr, &fl) < 0) {
123 printxval(lockfcmds, fl.l_type, "F_???");
124 tprintf(", whence=");
125 printxval(whence, fl.l_whence, "SEEK_???");
126 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
128 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
134 sprintflags(xlat, flags)
138 static char outstr[1024];
141 strcpy(outstr, "flags ");
143 for (; xlat->str; xlat++) {
144 if ((flags & xlat->val) == xlat->val) {
145 sprintf(outstr + strlen(outstr),
146 "%s%s", sep, xlat->str);
152 sprintf(outstr + strlen(outstr),
153 "%s%#x", sep, flags);
161 extern struct xlat openmodes[];
164 tprintf("%ld, ", tcp->u_arg[0]);
165 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
166 switch (tcp->u_arg[1]) {
169 if (printflags(fdflags, tcp->u_arg[2]) == 0)
172 case F_SETOWN: case F_DUPFD:
173 tprintf(", %ld", tcp->u_arg[2]);
177 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
180 case F_SETLK: case F_SETLKW:
182 printflock(tcp, tcp->u_arg[2], 0);
187 switch (tcp->u_arg[1]) {
189 case F_SETFD: case F_SETFL:
190 case F_SETLK: case F_SETLKW:
191 case F_SETOWN: case F_GETOWN:
194 if (tcp->u_rval == 0)
196 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
197 return RVAL_HEX|RVAL_STR;
199 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
200 return RVAL_HEX|RVAL_STR;
203 printflock(tcp, tcp->u_arg[2], 1);
206 tprintf(", %#lx", tcp->u_arg[2]);
220 tprintf("%ld, ", tcp->u_arg[0]);
221 if (!printflags(flockcmds, tcp->u_arg[1]))
233 tprintf("%ld", tcp->u_arg[0]);
243 tprintf("%ld", tcp->u_arg[0]);
253 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
259 sys_getdtablesize(tcp)
266 decode_select(tcp, args, bitness)
280 static char outstr[1024];
287 for (i = 0; i < 3; i++) {
294 tprintf(", %#lx", arg);
297 if (umove(tcp, arg, &fds) < 0) {
302 for (j = 0, sep = ""; j < nfds; j++) {
303 if (FD_ISSET(j, &fds)) {
304 tprintf("%s%u", sep, j);
312 else if (!verbose(tcp))
313 tprintf(", %#lx", args[4]);
314 else if (umove(tcp, args[4], &tv) < 0)
319 tv32=(struct timeval32*)&tv;
320 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
323 tprintf(", {%lu, %lu}",
324 (long) tv.tv_sec, (long) tv.tv_usec);
329 unsigned int cumlen = 0;
335 if ((nfds = tcp->u_rval) == 0) {
336 tcp->auxstr = "Timeout";
340 for (i = 0; i < 3; i++) {
344 tcp->auxstr = outstr;
346 if (!arg || umove(tcp, arg, &fds) < 0)
348 for (j = 0; j < args[0]; j++) {
349 if (FD_ISSET(j, &fds)) {
351 sprintf(str, "%s%s [%u", sep,
359 sprintf(str, " %u", j);
360 cumlen += strlen(str);
361 if (cumlen < sizeof(outstr))
372 /* This contains no useful information on SunOS. */
376 if (umove(tcp, args[4], &tv) >= 0) {
379 tv32=(struct timeval32*)&tv;
380 sprintf(str, "%sleft {%u, %u}", sep,
381 tv32->tv_sec, tv32->tv_usec);
384 sprintf(str, "%sleft {%lu, %lu}", sep,
385 (long) tv.tv_sec, (long) tv.tv_usec);
387 if ((cumlen += strlen(str)) < sizeof(outstr))
405 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
409 return decode_select(tcp, args, 0);
416 long *args = tcp->u_arg;
417 return decode_select(tcp, args, 1);
427 long *args = tcp->u_arg;
428 return decode_select(tcp, args, 0);