From 3d106c67088f64d961e4223e61f334d64154ccf9 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 15 Jan 2015 18:45:42 -0600 Subject: [PATCH] In waitpid emulation, restart waiting after signals. This matches the semantics the original hush code obtained by using the SA_RESTART flag when installing signal handlers, and avoids error messages about waitpid being interrupted. --- libbb/waitpid.emul.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libbb/waitpid.emul.c b/libbb/waitpid.emul.c index 996e0a9d5..cbdd2f587 100644 --- a/libbb/waitpid.emul.c +++ b/libbb/waitpid.emul.c @@ -84,6 +84,7 @@ pid_t waitpid_emul (pid_t pid, int *stat_loc, int options) sig_t prev_sig; int prev_errno; + restart: if (options & WNOHANG) { /* Arrange for a signal to interrupt the wait to simulate * non-blocking semantics. This might cause spurious @@ -108,9 +109,17 @@ pid_t waitpid_emul (pid_t pid, int *stat_loc, int options) * as a successful return with no finished child found. */ errno = prev_errno; return 0; + } else { + errno = wait_errno; } } + if (p == -1 && errno == EINTR) { + /* Hush originally set SA_RESTART option on all caught signals. + * GNO doesn't have this, so try to emulate it here. */ + goto restart; + } + if (p < 0) return p; if (p == pid || pid == -1)