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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
37 static struct xlat fcntlcmds[] = {
38 { F_DUPFD, "F_DUPFD" },
39 { F_GETFD, "F_GETFD" },
40 { F_SETFD, "F_SETFD" },
41 { F_GETFL, "F_GETFL" },
42 { F_SETFL, "F_SETFL" },
43 { F_GETLK, "F_GETLK" },
44 { F_SETLK, "F_SETLK" },
45 { F_SETLKW, "F_SETLKW" },
46 { F_GETOWN, "F_GETOWN" },
47 { F_SETOWN, "F_SETOWN" },
49 { F_RSETLK, "F_RSETLK" },
52 { F_RSETLKW, "F_RSETLKW" },
55 { F_RGETLK, "F_RGETLK" },
63 static struct xlat fdflags[] = {
65 { FD_CLOEXEC, "FD_CLOEXEC" },
72 static struct xlat flockcmds[] = {
73 { LOCK_SH, "LOCK_SH" },
74 { LOCK_EX, "LOCK_EX" },
75 { LOCK_NB, "LOCK_NB" },
76 { LOCK_UN, "LOCK_UN" },
82 static struct xlat lockfcmds[] = {
83 { F_RDLCK, "F_RDLCK" },
84 { F_WRLCK, "F_WRLCK" },
85 { F_UNLCK, "F_UNLCK" },
87 { F_EXLCK, "F_EXLCK" },
90 { F_SHLCK, "F_SHLCK" },
95 static struct xlat whence[] = {
96 { SEEK_SET, "SEEK_SET" },
97 { SEEK_CUR, "SEEK_CUR" },
98 { SEEK_END, "SEEK_END" },
104 printflock(tcp, addr, getlk)
111 if (umove(tcp, addr, &fl) < 0) {
116 printxval(lockfcmds, fl.l_type, "F_???");
117 tprintf(", whence=");
118 printxval(whence, fl.l_whence, "SEEK_???");
119 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
121 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
127 sprintflags(xlat, flags)
131 static char outstr[1024];
134 strcpy(outstr, "flags ");
136 for (; xlat->str; xlat++) {
137 if ((flags & xlat->val) == xlat->val) {
138 sprintf(outstr + strlen(outstr),
139 "%s%s", sep, xlat->str);
145 sprintf(outstr + strlen(outstr),
146 "%s%#x", sep, flags);
154 extern struct xlat openmodes[];
157 tprintf("%ld, ", tcp->u_arg[0]);
158 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
159 switch (tcp->u_arg[1]) {
162 if (printflags(fdflags, tcp->u_arg[2]) == 0)
165 case F_SETOWN: case F_DUPFD:
166 tprintf(", %ld", tcp->u_arg[2]);
170 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
173 case F_SETLK: case F_SETLKW:
175 printflock(tcp, tcp->u_arg[2], 0);
180 switch (tcp->u_arg[1]) {
182 case F_SETFD: case F_SETFL:
183 case F_SETLK: case F_SETLKW:
184 case F_SETOWN: case F_GETOWN:
187 if (tcp->u_rval == 0)
189 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
190 return RVAL_HEX|RVAL_STR;
192 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
193 return RVAL_HEX|RVAL_STR;
196 printflock(tcp, tcp->u_arg[2], 1);
199 tprintf(", %#lx", tcp->u_arg[2]);
213 tprintf("%ld, ", tcp->u_arg[0]);
214 if (!printflags(flockcmds, tcp->u_arg[1]))
226 tprintf("%ld", tcp->u_arg[0]);
236 tprintf("%ld", tcp->u_arg[0]);
246 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
252 sys_getdtablesize(tcp)
259 decode_select(tcp, args)
266 static char outstr[1024];
273 for (i = 0; i < 3; i++) {
280 tprintf(", %#lx", arg);
283 if (umove(tcp, arg, &fds) < 0) {
288 for (j = 0, sep = ""; j < nfds; j++) {
289 if (FD_ISSET(j, &fds)) {
290 tprintf("%s%u", sep, j);
298 else if (!verbose(tcp))
299 tprintf(", %#lx", args[4]);
300 else if (umove(tcp, args[4], &tv) < 0)
303 tprintf(", {%lu, %lu}",
304 (long) tv.tv_sec, (long) tv.tv_usec);
308 unsigned int cumlen = 0;
314 if ((nfds = tcp->u_rval) == 0) {
315 tcp->auxstr = "Timeout";
319 for (i = 0; i < 3; i++) {
323 tcp->auxstr = outstr;
325 if (!arg || umove(tcp, arg, &fds) < 0)
327 for (j = 0; j < args[0]; j++) {
328 if (FD_ISSET(j, &fds)) {
330 sprintf(str, "%s%s [%u", sep,
338 sprintf(str, " %u", j);
339 cumlen += strlen(str);
340 if (cumlen < sizeof(outstr))
351 /* This contains no useful information on SunOS. */
355 if (umove(tcp, args[4], &tv) >= 0)
356 sprintf(str, "%sleft {%lu, %lu}", sep,
357 (long) tv.tv_sec, (long) tv.tv_usec);
358 if ((cumlen += strlen(str)) < sizeof(outstr))
375 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
379 return decode_select(tcp, args);
388 long *args = tcp->u_arg;
389 return decode_select(tcp, args);