]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Intercept waitpid() so as to make it non-blocking. Yet another
authorJulian Seward <jseward@acm.org>
Sun, 13 Jul 2003 19:22:54 +0000 (19:22 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 13 Jul 2003 19:22:54 +0000 (19:22 +0000)
ghastly hack.  Roll on proper clonethread-based handling of blocking
syscalls.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1756

coregrind/vg_intercept.c

index 9d02dccc9d72120099177ea6e4c173a2f5a7f47b..2ee70a5565b332a29809bb420d2fb3b4604c45d8 100644 (file)
@@ -789,6 +789,37 @@ int sigsuspend ( /* const sigset_t * */ void* mask)
 }
 
 
+/* ================================ waitpid ============================ */
+
+#undef WNOHANG
+#define WNOHANG         0x00000001
+
+extern pid_t __libc_waitpid(pid_t pid, int *status, int options);
+
+pid_t waitpid(pid_t pid, int *status, int options)
+{
+   pid_t res;
+   struct vki_timespec nanosleep_interval;
+
+   if (options & WNOHANG)
+      return __libc_waitpid(pid,status,options);
+
+   options |= WNOHANG;
+   while (1) {
+      res = __libc_waitpid(pid,status,options);
+      if (res != 0)
+         return res;
+
+      nanosleep_interval.tv_sec  = 0;
+      nanosleep_interval.tv_nsec = 54 * 1000 * 1000; /* 54 milliseconds */
+      /* It's critical here that valgrind's nanosleep implementation
+         is nonblocking. */
+      VG_(nanosleep)( &nanosleep_interval, NULL);
+   }
+}
+
+#undef WNOHANG
+
 /* ---------------------------------------------------------------------
    Hook for running __libc_freeres once the program exits.
    ------------------------------------------------------------------ */