From 11c2a2dc3a734cae3027e8913833a1cdd8d1f26a Mon Sep 17 00:00:00 2001
From: "Tobias S. Josefowitz" <tobij@tobij.de>
Date: Wed, 17 Sep 2014 15:47:19 +0200
Subject: [PATCH] signal_handler: don't "randomly" change errno in
 receive_sigchild()

---
 src/signal_handler.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/signal_handler.c b/src/signal_handler.c
index b7fc502007..6c998b88b9 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
 
-- 
GitLab