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" },
64 static struct xlat fdflags[] = {
66 { FD_CLOEXEC, "FD_CLOEXEC" },
73 static struct xlat flockcmds[] = {
74 { LOCK_SH, "LOCK_SH" },
75 { LOCK_EX, "LOCK_EX" },
76 { LOCK_NB, "LOCK_NB" },
77 { LOCK_UN, "LOCK_UN" },
83 static struct xlat lockfcmds[] = {
84 { F_RDLCK, "F_RDLCK" },
85 { F_WRLCK, "F_WRLCK" },
86 { F_UNLCK, "F_UNLCK" },
88 { F_EXLCK, "F_EXLCK" },
91 { F_SHLCK, "F_SHLCK" },
96 static struct xlat whence[] = {
97 { SEEK_SET, "SEEK_SET" },
98 { SEEK_CUR, "SEEK_CUR" },
99 { SEEK_END, "SEEK_END" },
105 printflock(tcp, addr, getlk)
112 if (umove(tcp, addr, &fl) < 0) {
117 printxval(lockfcmds, fl.l_type, "F_???");
118 tprintf(", whence=");
119 printxval(whence, fl.l_whence, "SEEK_???");
120 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
122 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
128 sprintflags(xlat, flags)
132 static char outstr[1024];
135 strcpy(outstr, "flags ");
137 for (; xlat->str; xlat++) {
138 if ((flags & xlat->val) == xlat->val) {
139 sprintf(outstr + strlen(outstr),
140 "%s%s", sep, xlat->str);
146 sprintf(outstr + strlen(outstr),
147 "%s%#x", sep, flags);
155 extern struct xlat openmodes[];
158 tprintf("%ld, ", tcp->u_arg[0]);
159 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
160 switch (tcp->u_arg[1]) {
163 if (printflags(fdflags, tcp->u_arg[2]) == 0)
166 case F_SETOWN: case F_DUPFD:
167 tprintf(", %ld", tcp->u_arg[2]);
171 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
174 case F_SETLK: case F_SETLKW:
176 printflock(tcp, tcp->u_arg[2], 0);
181 switch (tcp->u_arg[1]) {
183 case F_SETFD: case F_SETFL:
184 case F_SETLK: case F_SETLKW:
185 case F_SETOWN: case F_GETOWN:
188 if (tcp->u_rval == 0)
190 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
191 return RVAL_HEX|RVAL_STR;
193 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
194 return RVAL_HEX|RVAL_STR;
197 printflock(tcp, tcp->u_arg[2], 1);
200 tprintf(", %#lx", tcp->u_arg[2]);
214 tprintf("%ld, ", tcp->u_arg[0]);
215 if (!printflags(flockcmds, tcp->u_arg[1]))
227 tprintf("%ld", tcp->u_arg[0]);
237 tprintf("%ld", tcp->u_arg[0]);
247 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
253 sys_getdtablesize(tcp)
260 decode_select(tcp, args, bitness)
274 static char outstr[1024];
281 for (i = 0; i < 3; i++) {
288 tprintf(", %#lx", arg);
291 if (umove(tcp, arg, &fds) < 0) {
296 for (j = 0, sep = ""; j < nfds; j++) {
297 if (FD_ISSET(j, &fds)) {
298 tprintf("%s%u", sep, j);
306 else if (!verbose(tcp))
307 tprintf(", %#lx", args[4]);
308 else if (umove(tcp, args[4], &tv) < 0)
313 tv32=(struct timeval32*)&tv;
314 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
317 tprintf(", {%lu, %lu}",
318 (long) tv.tv_sec, (long) tv.tv_usec);
323 unsigned int cumlen = 0;
329 if ((nfds = tcp->u_rval) == 0) {
330 tcp->auxstr = "Timeout";
334 for (i = 0; i < 3; i++) {
338 tcp->auxstr = outstr;
340 if (!arg || umove(tcp, arg, &fds) < 0)
342 for (j = 0; j < args[0]; j++) {
343 if (FD_ISSET(j, &fds)) {
345 sprintf(str, "%s%s [%u", sep,
353 sprintf(str, " %u", j);
354 cumlen += strlen(str);
355 if (cumlen < sizeof(outstr))
366 /* This contains no useful information on SunOS. */
370 if (umove(tcp, args[4], &tv) >= 0) {
373 tv32=(struct timeval32*)&tv;
374 sprintf(str, "%sleft {%u, %u}", sep,
375 tv32->tv_sec, tv32->tv_usec);
378 sprintf(str, "%sleft {%lu, %lu}", sep,
379 (long) tv.tv_sec, (long) tv.tv_usec);
381 if ((cumlen += strlen(str)) < sizeof(outstr))
399 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
403 return decode_select(tcp, args, 0);
410 long *args = tcp->u_arg;
411 return decode_select(tcp, args, 1);
421 long *args = tcp->u_arg;
422 return decode_select(tcp, args, 0);