]> granicus.if.org Git - strace/commitdiff
use __WALL for wait4 if we can
authorWichert Akkerman <wichert@deephackmode.org>
Wed, 28 Mar 2001 14:40:14 +0000 (14:40 +0000)
committerWichert Akkerman <wichert@deephackmode.org>
Wed, 28 Mar 2001 14:40:14 +0000 (14:40 +0000)
ChangeLog
strace.c

index 967d64a86426c0ba90249790eb782be2aca3d6ec..666775a05f65a94975ae87717f2869350453a6bc 100644 (file)
--- 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.
index 0e9242b1bdaa6918e1e6ec46bc4fa03ecf2b10c5..de2d56659a5bee4db15e6ffb764c6cfefc89dd27 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -1595,13 +1595,36 @@ trace()
        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);