Fix signal handler for SIGTERM, SIGINT and SIGQUIT.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 12 Oct 2021 01:40:11 +0000 (10:40 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 12 Oct 2021 01:40:11 +0000 (10:40 +0900)
It did not properly save errno and it was possible to overwrite errno.

src/protocol/child.c

index c4a432ee7c3ed5dbb30b2ecbccdc806f3fa28fea..f49c5ea26ecf72d188642adf4160ffd729acb895 100644 (file)
@@ -1076,10 +1076,10 @@ static RETSIGTYPE die(int sig)
 {
        int                     save_errno;
 
-       POOL_SETMASK(&BlockSig);
-
        save_errno = errno;
 
+       POOL_SETMASK(&BlockSig);
+
 #ifdef NOT_USED
        ereport(LOG,
                        (errmsg("child process received shutdown request signal %d", sig)));
@@ -1124,8 +1124,9 @@ static RETSIGTYPE die(int sig)
                        break;
        }
 
-       errno = save_errno;
        POOL_SETMASK(&UnBlockSig);
+
+       errno = save_errno;
 }
 
 /*