From e28b3ca91db0c6b2c82fd1516aabcca6c97767af Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Sat, 7 Sep 2013 19:50:54 +0100
Subject: [PATCH] Not ignoring SIGCHLD, cause it renders system() unusable on
 QNX

---
 build/main.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/build/main.c b/build/main.c
index d5fec663e..c6c36afdf 100644
--- a/build/main.c
+++ b/build/main.c
@@ -77,7 +77,15 @@ static struct mg_context *ctx;      // Set by start_mongoose()
 #endif /* !CONFIG_FILE */
 
 static void WINCDECL signal_handler(int sig_num) {
-  exit_flag = sig_num;
+#if !defined(_WIN32)
+  // Do not do the trick with ignoring SIGCHLD, cause not all OSes (e.g. QNX)
+  // reap zombies if SIGCHLD is ignored. On QNX, for example, waitpid()
+  // fails if SIGCHLD is ignored, making system() non-functional.
+  if (sig_num == SIGCHLD) {
+    do {} while (waitpid(-1, &sig_num, WNOHANG) > 0);
+  } else
+#endif
+  { exit_flag = sig_num; }
 }
 
 static void die(const char *fmt, ...) {
@@ -375,11 +383,6 @@ static void start_mongoose(int argc, char *argv[]) {
   signal(SIGTERM, signal_handler);
   signal(SIGINT, signal_handler);
 
-#if !defined(_WIN32)
-  // Also ignoring SIGCHLD to let the OS to reap zombies properly.
-  (void) signal(SIGCHLD, SIG_IGN);
-#endif
-
   // Start Mongoose
   memset(&callbacks, 0, sizeof(callbacks));
   callbacks.log_message = &log_message;
-- 
GitLab