use __WALL for wait4 if we can
diff --git a/ChangeLog b/ChangeLog
index 967d64a..666775a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2001-03-28  Wichert Akkerman <wakkerma@debian.org>
+
+  * strace.c: use __WALL as wait4 flag if it exists so we can properly
+    trace threaded programs
+
 2001-03-27  John Hughes <john@Calva.COM>
 
   * aclocal.m4: add check for endianness of long long.
diff --git a/strace.c b/strace.c
index 0e9242b..de2d566 100644
--- a/strace.c
+++ b/strace.c
@@ -1595,13 +1595,36 @@
 	struct tcb *tcp;
 #ifdef LINUX
 	struct rusage ru;
+#ifdef __WALL
+	static int wait4_options = __WALL;
+#endif
 #endif /* LINUX */
 
 	while (nprocs != 0) {
 		if (interactive)
 			sigprocmask(SIG_SETMASK, &empty_set, NULL);
 #ifdef LINUX
+#ifdef __WALL
+		pid = wait4(-1, &status, wait4_options, cflag ? &ru : NULL);
+		if ((wait4_options & __WALL) && errno == EINVAL) {
+			/* this kernel does not support __WALL */
+			wait4_options &= ~__WALL;
+			errno = 0;
+			pid = wait4(-1, &status, wait4_options,
+					cflag ? &ru : NULL);
+		}
+		if (!(wait4_options & __WALL) && errno == ECHILD) {
+			/* most likely a "cloned" process */
+			pid = wait4(-1, &status, __WCLONE,
+					cflag ? &ru : NULL);
+			if (pid == -1) {
+				fprintf(stderr, "strace: clone wait4 "
+						"failed: %s\n", strerror(errno));
+			}
+		}
+#else
 		pid = wait4(-1, &status, 0, cflag ? &ru : NULL);
+#endif /* __WALL */
 #endif /* LINUX */
 #ifdef SUNOS4
 		pid = wait(&status);