]> granicus.if.org Git - strace/blobdiff - wait.c
Mpersify RTC_* ioctl parser
[strace] / wait.c
diff --git a/wait.c b/wait.c
index 2e495dbf94117a5acf861a28eecff4a5a7b8c35b..64bd3b7d3efd8aa0f0a326e377ec0aa89aab0e59 100644 (file)
--- a/wait.c
+++ b/wait.c
@@ -1,3 +1,37 @@
+/*
+ * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
+ * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
+ * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
+ * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
+ * Copyright (c) 2002-2004 Roland McGrath <roland@redhat.com>
+ * 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>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #include "defs.h"
 
 #include <sys/wait.h>
@@ -83,10 +117,8 @@ printstatus(int status)
 }
 
 static int
-printwaitn(struct tcb *tcp, int n, int bitness)
+printwaitn(struct tcb *tcp, void (*const print_rusage)(struct tcb *, long))
 {
-       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
@@ -97,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]);
@@ -105,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]);
                }
@@ -125,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
 
@@ -146,18 +174,17 @@ SYS_FUNC(waitid)
 {
        if (entering(tcp)) {
                printxval(waitid_types, tcp->u_arg[0], "P_???");
-               tprintf(", %ld, ", tcp->u_arg[1]);
+               int pid = tcp->u_arg[1];
+               tprintf(", %d, ", pid);
        } else {
                /* siginfo */
                printsiginfo_at(tcp, tcp->u_arg[2]);
                /* options */
                tprints(", ");
                printflags(wait4_options, tcp->u_arg[3], "W???");
-               if (tcp->s_ent->nargs > 4) {
-                       /* usage */
-                       tprints(", ");
-                       printrusage(tcp, tcp->u_arg[4]);
-               }
+               /* usage */
+               tprints(", ");
+               printrusage(tcp, tcp->u_arg[4]);
        }
        return 0;
 }