honggfuzz: move thread pinging routine to a separate function
diff --git a/honggfuzz.c b/honggfuzz.c
index a4df08d..2f8755c 100644
--- a/honggfuzz.c
+++ b/honggfuzz.c
@@ -6,7 +6,7 @@
  * Authors: Robert Swiecki <swiecki@google.com>
  *          Felix Gröbert <groebert@google.com>
  *
- * Copyright 2010-2018 by Google Inc. All Rights Reserved.
+ * Copyright 2010-2019 by Google Inc. All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may
  * not use this file except in compliance with the License. You may obtain
@@ -124,6 +124,7 @@
     sigaddset(&ss, SIGALRM);
     sigaddset(&ss, SIGPIPE);
     sigaddset(&ss, SIGIO);
+    sigaddset(&ss, SIGCHLD);
     if (sigprocmask(SIG_BLOCK, &ss, NULL) != 0) {
         PLOG_F("pthread_sigmask(SIG_BLOCK)");
     }
@@ -172,6 +173,14 @@
         elapsed_sec, exec_per_sec);
 }
 
+static void pingThreads(honggfuzz_t* hfuzz, pthread_t* threads) {
+    for (size_t i = 0; i < hfuzz->threads.threadsMax; i++) {
+        if (pthread_kill(threads[i], SIGUSR1) != 0) {
+            PLOG_W("pthread_kill(thread=%zu, SIGUSR1)", i);
+        }
+    }
+}
+
 int main(int argc, char** argv) {
     /*
      * Work around CygWin/MinGW
@@ -247,13 +256,12 @@
             display_display(&hfuzz);
             showDisplay = false;
         }
-        /* Ping all threads with USR1, so they can check e.g. time limits, by returning with EINTR
-         * from wait() */
-        for (size_t i = 0; i < hfuzz.threads.threadsMax; i++) {
-            if (pthread_kill(threads[i], SIGUSR1) != 0) {
-                PLOG_W("pthread_kill(thread=%zu, SIGUSR1)", i);
-            }
-        }
+        /*
+         * Ping all threads with USR1, so they can check e.g. time limits, by returning with EINTR
+         * from wait()
+         */
+        pingThreads(&hfuzz, threads);
+
         if (ATOMIC_GET(sigReceived) > 0) {
             LOG_I("Signal %d (%s) received, terminating", ATOMIC_GET(sigReceived),
                 strsignal(ATOMIC_GET(sigReceived)));
@@ -270,6 +278,9 @@
     }
 
     fuzz_setTerminating();
+
+    /* Ping threads one last time */
+    pingThreads(&hfuzz, threads);
     fuzz_threadsStop(&hfuzz, threads);
 
     /* Clean-up global buffers */