From 1697c192acc763682ee9883aa94fe871246403c0 Mon Sep 17 00:00:00 2001 From: Thomas Abraham Date: Thu, 25 Apr 2019 14:56:22 -0400 Subject: [PATCH 1/3] lib/spawn.c run_command: don't loop forever if waitpid() is returning ECHILD If SIGCHILD is being ignored, waitpid() will forever error with ECHILD and this loop with never end, so don't loop if it erros with ECHILD. --- lib/spawn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/spawn.c b/lib/spawn.c index fc4ad95c..79f5054e 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -68,8 +68,9 @@ int run_command (const char *cmd, const char *argv[], do { wpid = waitpid (pid, status, 0); - } while ( ((pid_t)-1 == wpid && errno == EINTR) - || ((pid_t)-1 != wpid && wpid != pid)); + } while ( ((pid_t)-1 == wpid && errno != ECHILD) + && (((pid_t)-1 == wpid && errno == EINTR) + || ((pid_t)-1 != wpid && wpid != pid))); if ((pid_t)-1 == wpid) { fprintf (stderr, "%s: waitpid (status: %d): %s\n", From 8d39357c840d3a529697144790f02307e5b8731b Mon Sep 17 00:00:00 2001 From: Thomas Abraham Date: Mon, 6 May 2019 14:23:58 -0400 Subject: [PATCH 2/3] Revert "lib/spawn.c run_command: don't loop forever if waitpid() is returning ECHILD" This reverts commit 1697c192acc763682ee9883aa94fe871246403c0. --- lib/spawn.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/spawn.c b/lib/spawn.c index 79f5054e..fc4ad95c 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -68,9 +68,8 @@ int run_command (const char *cmd, const char *argv[], do { wpid = waitpid (pid, status, 0); - } while ( ((pid_t)-1 == wpid && errno != ECHILD) - && (((pid_t)-1 == wpid && errno == EINTR) - || ((pid_t)-1 != wpid && wpid != pid))); + } while ( ((pid_t)-1 == wpid && errno == EINTR) + || ((pid_t)-1 != wpid && wpid != pid)); if ((pid_t)-1 == wpid) { fprintf (stderr, "%s: waitpid (status: %d): %s\n", From 82fa6eccf9326f8002e7c969a0c06faffc3113f1 Mon Sep 17 00:00:00 2001 From: Thomas Abraham Date: Mon, 6 May 2019 14:26:14 -0400 Subject: [PATCH 3/3] lib/spawn.c run_command: don't loop forever if waitpid() is returning ECHILD If SIGCHILD is being ignored, waitpid() will forever error with ECHILD and this loop with never end, so don't loop if it errors with ECHILD. --- lib/spawn.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/spawn.c b/lib/spawn.c index fc4ad95c..d0b5fb26 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -68,6 +68,8 @@ int run_command (const char *cmd, const char *argv[], do { wpid = waitpid (pid, status, 0); + if ((pid_t)-1 == wpid && errno == ECHILD) + break; } while ( ((pid_t)-1 == wpid && errno == EINTR) || ((pid_t)-1 != wpid && wpid != pid));