]> granicus.if.org Git - strace/commitdiff
poll.c: use print_array function
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 7 May 2016 23:09:09 +0000 (23:09 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 7 May 2016 23:37:53 +0000 (23:37 +0000)
* poll.c (print_pollfd): Change for use as print_array callback.
(decode_poll_entering): Use print_array.
* tests/poll.c: Update.
* tests/poll.test: Update.

poll.c
tests/poll.c
tests/poll.test

diff --git a/poll.c b/poll.c
index f72c985e2ab0dac9f994137188b1aa68a9b32ab9..afe0493acdb1771331ce1f0b63f9bb7eae870e5f 100644 (file)
--- a/poll.c
+++ b/poll.c
 
 #include "xlat/pollflags.h"
 
-static void
-print_pollfd(struct tcb *tcp, const struct pollfd *fds)
+static bool
+print_pollfd(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 {
+       const struct pollfd *fds = elem_buf;
+
        tprints("{fd=");
        printfd(tcp, fds->fd);
        if (fds->fd >= 0) {
@@ -41,55 +43,20 @@ print_pollfd(struct tcb *tcp, const struct pollfd *fds)
                printflags(pollflags, fds->events, "POLL???");
        }
        tprints("}");
+
+       return true;
 }
 
-static int
+static void
 decode_poll_entering(struct tcb *tcp)
 {
-       struct pollfd fds;
+       const unsigned long addr = tcp->u_arg[0];
        const unsigned int nfds = tcp->u_arg[1];
-       const unsigned long size = sizeof(fds) * nfds;
-       const unsigned long start = tcp->u_arg[0];
-       const unsigned long end = start + size;
-       const unsigned long max_printed =
-               abbrev(tcp) ? max_strlen : (unsigned int) -1;
-
-       if (!verbose(tcp) || !start || !nfds ||
-           size / sizeof(fds) != nfds || end < start) {
-               printaddr(start);
-               tprintf(", %u, ", nfds);
-               return 0;
-       }
-
-       if (umove(tcp, start, &fds) < 0) {
-               printaddr(start);
-               tprintf(", %u, ", nfds);
-               return 0;
-       }
-
-       tprints("[");
-       if (max_printed) {
-               unsigned long printed = 1;
-               unsigned long cur = start + sizeof(fds);
-
-               print_pollfd(tcp, &fds);
-               for (; cur < end; ++printed, cur += sizeof(fds)) {
-                       tprints(", ");
-                       if (printed >= max_printed) {
-                               tprints("...");
-                               break;
-                       }
-                       if (umove_or_printaddr(tcp, cur, &fds))
-                               break;
-                       print_pollfd(tcp, &fds);
-
-               }
-       } else {
-               tprints("...");
-       }
-       tprintf("], %u, ", nfds);
+       struct pollfd fds;
 
-       return 0;
+       print_array(tcp, addr, nfds, &fds, sizeof(fds),
+                   umoven_or_printaddr, print_pollfd, 0);
+       tprintf(", %u, ", nfds);
 }
 
 static int
@@ -184,16 +151,17 @@ decode_poll_exiting(struct tcb *tcp, const long pts)
 SYS_FUNC(poll)
 {
        if (entering(tcp)) {
-               int rc = decode_poll_entering(tcp);
+               decode_poll_entering(tcp);
+               int timeout = tcp->u_arg[2];
 
 #ifdef INFTIM
-               if (INFTIM == (int) tcp->u_arg[2])
+               if (INFTIM == timeout)
                        tprints("INFTIM");
                else
 #endif
-                       tprintf("%d", (int) tcp->u_arg[2]);
+                       tprintf("%d", timeout);
 
-               return rc;
+               return 0;
        } else {
                return decode_poll_exiting(tcp, 0);
        }
@@ -202,7 +170,7 @@ SYS_FUNC(poll)
 SYS_FUNC(ppoll)
 {
        if (entering(tcp)) {
-               int rc = decode_poll_entering(tcp);
+               decode_poll_entering(tcp);
 
                print_timespec(tcp, tcp->u_arg[2]);
                tprints(", ");
@@ -210,7 +178,7 @@ SYS_FUNC(ppoll)
                print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
                tprintf(", %lu", tcp->u_arg[4]);
 
-               return rc;
+               return 0;
        } else {
                return decode_poll_exiting(tcp, tcp->u_arg[2]);
        }
index 045aca0e9ba350a44b716ab6c56f8d8d01d3909a..551e9b44d13c6420174e88e84cdc709384c2e62c 100644 (file)
@@ -91,16 +91,15 @@ print_pollfd_array_entering(const struct pollfd *const pfd,
        for (i = 0; i < size; ++i) {
                if (i)
                        tprintf(", ");
-               if (i >= abbrev) {
-                       tprintf("...");
+               if (i >= valid) {
+                       tprintf("%p", &pfd[i]);
                        break;
                }
-               if (i < valid)
-                       print_pollfd_entering(&pfd[i]);
-               else {
-                       tprintf("%p", &pfd[i]);
+               if (i >= abbrev) {
+                       tprintf("...");
                        break;
                }
+               print_pollfd_entering(&pfd[i]);
        }
        tprintf("]");
 }
@@ -185,7 +184,7 @@ main(int ac, char **av)
        int rc = syscall(__NR_poll, tail_fds0, 0, timeout);
        assert(rc == 0);
 
-       tprintf("poll(%p, 0, %d) = %d (Timeout)\n", tail_fds0, timeout, rc);
+       tprintf("poll([], 0, %d) = %d (Timeout)\n", timeout, rc);
 
        rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
        assert(rc == 3);
index 1834c1fc12d6ae55515fe38c596673e91b842405..b74be29e60e3eabf2673f541ebcc234202dbcb49 100755 (executable)
@@ -5,12 +5,12 @@
 . "${srcdir=.}/init.sh"
 
 run_prog > /dev/null
-run_strace -a18 -vepoll $args > "$OUT"
+run_strace -a16 -vepoll $args > "$OUT"
 match_diff "$LOG" "$OUT"
 
 for abbrev in 0 1 2 3 4 5; do
        run_prog "./$NAME" $abbrev > /dev/null
-       run_strace -a18 -epoll -s$abbrev $args > "$OUT"
+       run_strace -a16 -epoll -s$abbrev $args > "$OUT"
        match_diff "$LOG" "$OUT"
 done