[PATCH] on Linux, use ints, not longs, for PIDs in waitpid decoding

Denys Vlasenko dvlasenk at redhat.com
Thu Apr 16 12:12:29 UTC 2009


Hi,

I observed several times wait4(4294967295, ...) instead of wait4(-1, ...).
Kernel code inspection shows that kernel always stores PID
into pid_t typed variable, and pid_t is invariably an int
on all architectures. Thus, 4294967295 will be seen as -1 in kernel,
even on 64-bit machines.

Here is the patch I am applying to fix this:
--
vda


--- strace.0/process.c	2009-04-14 14:51:00.000000000 +0200
+++ strace.1/process.c	2009-04-15 16:49:24.000000000 +0200
@@ -1998,21 +1998,24 @@ printwaitn(struct tcb *tcp, int n, int b
 	int exited = 0;
 
 	if (entering(tcp)) {
-		/*
-		 * Sign-extend a 32-bit value when that's what it is.
-		 *
-		 * NB: On Linux, kernel-side pid_t is typedef'ed to int
-		 * on all arches; also, glibc-2.8 truncates wait3 and wait4
+#ifdef LINUX
+		/* On Linux, kernel-side pid_t is typedef'ed to int
+		 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
 		 * pid argument to int on 64bit arches, producing,
 		 * for example, wait4(4294967295, ...) instead of -1
-		 * in strace.
-		 * Therefore, maybe it makes sense to *unconditionally*
-		 * widen int to long here...
+		 * in strace. We have to use int here, not long.
+		 */
+		int pid = tcp->u_arg[0];
+		tprintf("%d, ", pid);
+#else
+		/*
+		 * Sign-extend a 32-bit value when that's what it is.
 		 */
 		long pid = tcp->u_arg[0];
 		if (personality_wordsize[current_personality] < sizeof pid)
 			pid = (long) (int) pid;
 		tprintf("%ld, ", pid);
+#endif
 	} else {
 		/* status */
 		if (!tcp->u_arg[1])






More information about the Strace-devel mailing list