+/*
+ * 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>
}
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
int pid = tcp->u_arg[0];
tprintf("%d, ", pid);
} else {
+ int status;
+
/* status */
- if (!tcp->u_arg[1])
- tprints("NULL");
- else if (syserror(tcp) || tcp->u_rval == 0)
- tprintf("%#lx", tcp->u_arg[1]);
- else if (umove(tcp, tcp->u_arg[1], &status) < 0)
- tprints("[?]");
- else
+ if (tcp->u_rval == 0)
+ printaddr(tcp->u_arg[1]);
+ else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &status))
printstatus(status);
/* options */
tprints(", ");
printflags(wait4_options, tcp->u_arg[2], "W???");
- if (n == 4) {
- tprints(", ");
+ if (print_rusage) {
/* usage */
- if (!tcp->u_arg[3])
- tprints("NULL");
- else 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
- tprintf("%#lx", tcp->u_arg[3]);
+ printaddr(tcp->u_arg[3]);
}
}
return 0;
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
{
if (entering(tcp)) {
printxval(waitid_types, tcp->u_arg[0], "P_???");
- tprintf(", %ld, ", tcp->u_arg[1]);
- }
- else {
+ 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(", ");
- if (!tcp->u_arg[4])
- tprints("NULL");
- else if (tcp->u_error)
- tprintf("%#lx", tcp->u_arg[4]);
- else
- printrusage(tcp, tcp->u_arg[4]);
- }
+ /* usage */
+ tprints(", ");
+ printrusage(tcp, tcp->u_arg[4]);
}
return 0;
}