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.
39 #include <sys/epoll.h>
42 #if HAVE_LONG_LONG_OFF_T
44 * Hacks for systems that have a long long off_t
46 #define flock64 flock /* Horrid hack */
47 #define printflock printflock64 /* Horrider hack */
51 static const struct xlat fcntlcmds[] = {
52 { F_DUPFD, "F_DUPFD" },
53 { F_GETFD, "F_GETFD" },
54 { F_SETFD, "F_SETFD" },
55 { F_GETFL, "F_GETFL" },
56 { F_SETFL, "F_SETFL" },
57 { F_GETLK, "F_GETLK" },
58 { F_SETLK, "F_SETLK" },
59 { F_SETLKW, "F_SETLKW" },
60 { F_GETOWN, "F_GETOWN" },
61 { F_SETOWN, "F_SETOWN" },
63 { F_RSETLK, "F_RSETLK" },
66 { F_RSETLKW, "F_RSETLKW" },
69 { F_RGETLK, "F_RGETLK" },
75 { F_SETSIG, "F_SETSIG" },
78 { F_GETSIG, "F_GETSIG" },
81 { F_CHKFL, "F_CHKFL" },
84 { F_DUP2FD, "F_DUP2FD" },
87 { F_ALLOCSP, "F_ALLOCSP" },
90 { F_ISSTREAM, "F_ISSTREAM" },
96 { F_NPRIV, "F_NPRIV" },
99 { F_QUOTACL, "F_QUOTACL" },
102 { F_BLOCKS, "F_BLOCKS" },
105 { F_BLKSIZE, "F_BLKSIZE" },
108 { F_GETOWN, "F_GETOWN" },
111 { F_SETOWN, "F_SETOWN" },
114 { F_REVOKE, "F_REVOKE" },
117 { F_SETLK, "F_SETLK" },
120 { F_SETLKW, "F_SETLKW" },
123 { F_FREESP, "F_FREESP" },
126 { F_GETLK, "F_GETLK" },
129 { F_SETLK64, "F_SETLK64" },
132 { F_SETLKW64, "F_SETLKW64" },
135 { F_FREESP64, "F_FREESP64" },
138 { F_GETLK64, "F_GETLK64" },
141 { F_SHARE, "F_SHARE" },
144 { F_UNSHARE, "F_UNSHARE" },
149 static const struct xlat fdflags[] = {
151 { FD_CLOEXEC, "FD_CLOEXEC" },
158 static const struct xlat flockcmds[] = {
159 { LOCK_SH, "LOCK_SH" },
160 { LOCK_EX, "LOCK_EX" },
161 { LOCK_NB, "LOCK_NB" },
162 { LOCK_UN, "LOCK_UN" },
168 static const struct xlat lockfcmds[] = {
169 { F_RDLCK, "F_RDLCK" },
170 { F_WRLCK, "F_WRLCK" },
171 { F_UNLCK, "F_UNLCK" },
173 { F_EXLCK, "F_EXLCK" },
176 { F_SHLCK, "F_SHLCK" },
181 static const struct xlat whence[] = {
182 { SEEK_SET, "SEEK_SET" },
183 { SEEK_CUR, "SEEK_CUR" },
184 { SEEK_END, "SEEK_END" },
188 #ifndef HAVE_LONG_LONG_OFF_T
191 printflock(tcp, addr, getlk)
198 if (umove(tcp, addr, &fl) < 0) {
203 printxval(lockfcmds, fl.l_type, "F_???");
204 tprintf(", whence=");
205 printxval(whence, fl.l_whence, "SEEK_???");
206 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
208 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
214 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
217 printflock64(tcp, addr, getlk)
224 if (umove(tcp, addr, &fl) < 0) {
229 printxval(lockfcmds, fl.l_type, "F_???");
230 tprintf(", whence=");
231 printxval(whence, fl.l_whence, "SEEK_???");
232 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
234 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
241 sprintflags(xlat, flags)
242 const struct xlat *xlat;
245 static char outstr[1024];
248 strcpy(outstr, "flags ");
250 for (; xlat->str; xlat++) {
251 if ((flags & xlat->val) == xlat->val) {
252 sprintf(outstr + strlen(outstr),
253 "%s%s", sep, xlat->str);
259 sprintf(outstr + strlen(outstr),
260 "%s%#x", sep, flags);
268 extern const struct xlat openmodes[];
271 tprintf("%ld, ", tcp->u_arg[0]);
272 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
273 switch (tcp->u_arg[1]) {
276 if (printflags(fdflags, tcp->u_arg[2]) == 0)
279 case F_SETOWN: case F_DUPFD:
280 tprintf(", %ld", tcp->u_arg[2]);
284 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
287 case F_SETLK: case F_SETLKW:
292 printflock(tcp, tcp->u_arg[2], 0);
298 /* Linux glibc defines SETLK64 as SETLK,
299 even though the kernel has different values - as does Solaris. */
300 #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
303 #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
307 printflock64(tcp, tcp->u_arg[2], 0);
313 switch (tcp->u_arg[1]) {
315 case F_SETFD: case F_SETFL:
316 case F_SETLK: case F_SETLKW:
317 case F_SETOWN: case F_GETOWN:
320 if (tcp->u_rval == 0)
322 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
323 return RVAL_HEX|RVAL_STR;
325 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
326 return RVAL_HEX|RVAL_STR;
329 printflock(tcp, tcp->u_arg[2], 1);
332 #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
336 printflock64(tcp, tcp->u_arg[2], 1);
340 tprintf(", %#lx", tcp->u_arg[2]);
354 tprintf("%ld, ", tcp->u_arg[0]);
355 if (!printflags(flockcmds, tcp->u_arg[1]))
367 tprintf("%ld", tcp->u_arg[0]);
377 tprintf("%ld", tcp->u_arg[0]);
387 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
393 sys_getdtablesize(tcp)
400 decode_select(tcp, args, bitness)
414 static char outstr[1024];
421 for (i = 0; i < 3; i++) {
428 tprintf(", %#lx", arg);
431 if (umove(tcp, arg, &fds) < 0) {
436 for (j = 0, sep = ""; j < nfds; j++) {
437 if (FD_ISSET(j, &fds)) {
438 tprintf("%s%u", sep, j);
446 else if (!verbose(tcp))
447 tprintf(", %#lx", args[4]);
448 else if (umove(tcp, args[4], &tv) < 0)
453 tv32=(struct timeval32*)&tv;
454 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
457 tprintf(", {%lu, %lu}",
458 (long) tv.tv_sec, (long) tv.tv_usec);
463 unsigned int cumlen = 0;
469 if ((nfds = tcp->u_rval) == 0) {
470 tcp->auxstr = "Timeout";
474 for (i = 0; i < 3; i++) {
478 tcp->auxstr = outstr;
480 if (!arg || umove(tcp, arg, &fds) < 0)
482 for (j = 0; j < args[0]; j++) {
483 if (FD_ISSET(j, &fds)) {
485 sprintf(str, "%s%s [%u", sep,
493 sprintf(str, " %u", j);
494 cumlen += strlen(str);
495 if (cumlen < sizeof(outstr))
506 /* This contains no useful information on SunOS. */
510 if (umove(tcp, args[4], &tv) >= 0) {
513 tv32=(struct timeval32*)&tv;
514 sprintf(str, "%sleft {%u, %u}", sep,
515 tv32->tv_sec, tv32->tv_usec);
518 sprintf(str, "%sleft {%lu, %lu}", sep,
519 (long) tv.tv_sec, (long) tv.tv_usec);
521 if ((cumlen += strlen(str)) < sizeof(outstr))
539 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
543 return decode_select(tcp, args, 0);
551 long *args = tcp->u_arg;
552 return decode_select(tcp, args, 1);
556 static struct xlat epollctls[] = {
557 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
558 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
559 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
563 static struct xlat epollevents[] = {
564 { EPOLLIN, "EPOLLIN" },
565 { EPOLLPRI, "EPOLLPRI" },
566 { EPOLLOUT, "EPOLLOUT" },
567 { EPOLLRDNORM, "EPOLLRDNORM" },
568 { EPOLLRDBAND, "EPOLLRDBAND" },
569 { EPOLLWRNORM, "EPOLLWRNORM" },
570 { EPOLLWRBAND, "EPOLLWRBAND" },
571 { EPOLLMSG, "EPOLLMSG" },
572 { EPOLLERR, "EPOLLERR" },
573 { EPOLLHUP, "EPOLLHUP" },
574 { EPOLLONESHOT, "EPOLLONESHOT" },
575 { EPOLLET, "EPOLLET" },
580 sys_epoll_create(tcp)
584 tprintf("%ld", tcp->u_arg[0]);
589 print_epoll_event(ev)
590 struct epoll_event *ev;
593 if (printflags(epollevents, ev->events) == 0)
595 /* We cannot know what format the program uses, so print u32 and u64
596 which will cover every value. */
597 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
598 ev->data.u32, ev->data.u64);
606 struct epoll_event ev;
607 tprintf("%ld, ", tcp->u_arg[0]);
608 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
609 tprintf(", %ld, ", tcp->u_arg[2]);
610 if (tcp->u_arg[3] == 0)
612 else if (umove(tcp, tcp->u_arg[3], &ev) < 0)
615 print_epoll_event(&ev);
625 tprintf("%ld, ", tcp->u_arg[0]);
628 tprintf("%lx", tcp->u_arg[1]);
629 else if (tcp->u_rval == 0)
632 struct epoll_event evs[tcp->u_rval];
633 if (umove(tcp, tcp->u_arg[1], evs) < 0)
638 for (i = 0; i < tcp->u_rval; ++i) {
641 print_epoll_event(&evs[i]);
646 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
656 long *args = tcp->u_arg;
657 return decode_select(tcp, args, 0);