igt_core: Read manpages more carefully for WNOHANG
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 24 Jul 2014 11:00:57 +0000 (12:00 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 24 Jul 2014 11:02:36 +0000 (12:02 +0100)
/me hides

I thought it said it would not return for a signal and stopped thinking.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
lib/igt_core.c

index 1287ff6..b0800e8 100644 (file)
@@ -791,16 +791,24 @@ static void reset_helper_process_list(void)
        helper_process_count = 0;
 }
 
-static void fork_helper_exit_handler(int sig)
+static int __waitpid(pid_t pid)
 {
-       int status;
+       int status = -1;
+       while (waitpid(pid, &status, 0) == -1 &&
+              errno == EINTR)
+               ;
 
+       return status;
+}
+
+static void fork_helper_exit_handler(int sig)
+{
        /* Inside a signal handler, play safe */
        for (int i = 0; i < ARRAY_SIZE(helper_process_pids); i++) {
                pid_t pid = helper_process_pids[i];
                if (pid != -1) {
                        kill(pid, SIGTERM);
-                       waitpid(pid, &status, WNOHANG);
+                       __waitpid(pid);
                        helper_process_count--;
                }
        }
@@ -851,11 +859,11 @@ bool __igt_fork_helper(struct igt_helper_process *proc)
  */
 int igt_wait_helper(struct igt_helper_process *proc)
 {
-       int status = -1;
+       int status;
 
        assert(proc->running);
 
-       waitpid(proc->pid, &status, WNOHANG);
+       status = __waitpid(proc->pid);
 
        proc->running = false;