This is an automated email from the ASF dual-hosted git repository.

maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit ab63a723391779aa8c9fce386f062bf033872cc3
Author: Thomas Munro <[email protected]>
AuthorDate: Sat Jul 16 10:59:52 2022 +1200

    Make dsm_impl_posix_resize more future-proof.
    
    Commit 4518c798 blocks signals for a short region of code, but it
    assumed that whatever called it had the signal mask set to UnBlockSig on
    entry.  That may be true today (or may even not be, in extensions in the
    wild), but it would be better not to make that assumption.  We should
    save-and-restore the caller's signal mask.
    
    The PG_SETMASK() portability macro couldn't be used for that, which is
    why it wasn't done before.  But... considering that commit a65e0864
    established back in 9.6 that supported POSIX systems have sigprocmask(),
    and that this is POSIX-only code, there is no reason not to use standard
    sigprocmask() directly to achieve that.
    
    Back-patch to all supported releases, like 4518c798 and 80845b7c.
    
    Reviewed-by: Alvaro Herrera <[email protected]>
    Reviewed-by: Tom Lane <[email protected]>
    Discussion: 
https://postgr.es/m/CA%2BhUKGKx6Biq7_UuV0kn9DW%2B8QWcpJC1qwhizdtD9tN-fn0H0g%40mail.gmail.com
---
 src/backend/storage/ipc/dsm_impl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/backend/storage/ipc/dsm_impl.c 
b/src/backend/storage/ipc/dsm_impl.c
index 873ed80e32..46a60e1b89 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -49,6 +49,7 @@
 #include "postgres.h"
 
 #include <fcntl.h>
+#include <signal.h>
 #include <unistd.h>
 #ifndef WIN32
 #include <sys/mman.h>
@@ -355,6 +356,7 @@ dsm_impl_posix_resize(int fd, off_t size)
 {
        int                     rc;
        int                     save_errno;
+       sigset_t        save_sigmask;
 
        /*
         * Block all blockable signals, except SIGQUIT.  posix_fallocate() can 
run
@@ -363,7 +365,7 @@ dsm_impl_posix_resize(int fd, off_t size)
         * conflicts), the retry loop might never succeed.
         */
        if (IsUnderPostmaster)
-               PG_SETMASK(&BlockSig);
+               sigprocmask(SIG_SETMASK, &BlockSig, &save_sigmask);
 
        /* Truncate (or extend) the file to the requested size. */
        do
@@ -406,7 +408,7 @@ dsm_impl_posix_resize(int fd, off_t size)
        if (IsUnderPostmaster)
        {
                save_errno = errno;
-               PG_SETMASK(&UnBlockSig);
+               sigprocmask(SIG_SETMASK, &save_sigmask, NULL);
                errno = save_errno;
        }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to