diff --git a/src/signal_handler.c b/src/signal_handler.c index b7fc5020070d12afe6f10a8e80f8ef197f079b31..6c998b88b980e0fd62df8c6a4cac598a8df79b63 100644 --- a/src/signal_handler.c +++ b/src/signal_handler.c @@ -1186,6 +1186,7 @@ static RETSIGTYPE receive_sigchild(int UNUSED(signum)) { pid_t pid; WAITSTATUSTYPE status; + int masked_errno = errno; PROC_FPRINTF((stderr, "[%d] receive_sigchild\n", getpid())); @@ -1224,6 +1225,11 @@ static RETSIGTYPE receive_sigchild(int UNUSED(signum)) register_signal(SIGCHLD); SAFE_FIFO_DEBUG_END(); + + /* The wait and possibly the signal stuff can obfuscate errno here, + * while outside of the signal handler we might be in, say, the backend, + * and cause a bit of trouble there. Let's leave errno as we found it. */ + errno = masked_errno; } #endif