]> granicus.if.org Git - strace/blobdiff - wait.c
nlattr: add UID/GID netlink attribute decoders
[strace] / wait.c
diff --git a/wait.c b/wait.c
index fc7601799a56ee9c139c96eaba097f7ced757e24..c1d1dff24952b6be91feeb39232a9e3ccf0be834 100644 (file)
--- a/wait.c
+++ b/wait.c
@@ -7,6 +7,7 @@
  * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
  * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com>
  * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2014-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,6 +34,7 @@
  */
 
 #include "defs.h"
+#include "ptrace.h"
 
 #include <sys/wait.h>
 
@@ -57,7 +59,6 @@
 # define W_CONTINUED 0xffff
 #endif
 
-#include "ptrace.h"
 #include "xlat/ptrace_events.h"
 
 static int
@@ -76,14 +77,12 @@ printstatus(int status)
                        signame(sig & 0x7f),
                        sig & 0x80 ? " | 0x80" : "");
                status &= ~W_STOPCODE(sig);
-       }
-       else if (WIFSIGNALED(status)) {
+       } else if (WIFSIGNALED(status)) {
                tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
                        signame(WTERMSIG(status)),
                        WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
                status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
-       }
-       else if (WIFEXITED(status)) {
+       } else if (WIFEXITED(status)) {
                tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
                        WEXITSTATUS(status));
                exited = 1;
@@ -117,10 +116,9 @@ printstatus(int status)
 }
 
 static int
-printwaitn(struct tcb *tcp, int n, int bitness)
+printwaitn(struct tcb *const tcp,
+          void (*const print_rusage)(struct tcb *, kernel_ulong_t))
 {
-       int status;
-
        if (entering(tcp)) {
                /* On Linux, kernel-side pid_t is typedef'ed to int
                 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
@@ -131,6 +129,8 @@ printwaitn(struct tcb *tcp, int n, int bitness)
                int pid = tcp->u_arg[0];
                tprintf("%d, ", pid);
        } else {
+               int status;
+
                /* status */
                if (tcp->u_rval == 0)
                        printaddr(tcp->u_arg[1]);
@@ -139,17 +139,11 @@ printwaitn(struct tcb *tcp, int n, int bitness)
                /* options */
                tprints(", ");
                printflags(wait4_options, tcp->u_arg[2], "W???");
-               if (n == 4) {
-                       tprints(", ");
+               if (print_rusage) {
                        /* usage */
-                       if (tcp->u_rval > 0) {
-#ifdef ALPHA
-                               if (bitness)
-                                       printrusage32(tcp, tcp->u_arg[3]);
-                               else
-#endif
-                                       printrusage(tcp, tcp->u_arg[3]);
-                       }
+                       tprints(", ");
+                       if (tcp->u_rval > 0)
+                               print_rusage(tcp, tcp->u_arg[3]);
                        else
                                printaddr(tcp->u_arg[3]);
                }
@@ -159,18 +153,18 @@ printwaitn(struct tcb *tcp, int n, int bitness)
 
 SYS_FUNC(waitpid)
 {
-       return printwaitn(tcp, 3, 0);
+       return printwaitn(tcp, NULL);
 }
 
 SYS_FUNC(wait4)
 {
-       return printwaitn(tcp, 4, 0);
+       return printwaitn(tcp, printrusage);
 }
 
 #ifdef ALPHA
 SYS_FUNC(osf_wait4)
 {
-       return printwaitn(tcp, 4, 1);
+       return printwaitn(tcp, printrusage32);
 }
 #endif