Skip to content

Commit 1661c40

Browse files
committed
Make dsm_impl_posix_resize more future-proof.
Commit 4518c79 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 a65e086 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 4518c79 and 80845b7. Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CA%2BhUKGKx6Biq7_UuV0kn9DW%2B8QWcpJC1qwhizdtD9tN-fn0H0g%40mail.gmail.com
1 parent 27b8f73 commit 1661c40

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/storage/ipc/dsm_impl.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "miscadmin.h"
5151

5252
#include <fcntl.h>
53+
#include <signal.h>
5354
#include <unistd.h>
5455
#ifndef WIN32
5556
#include <sys/mman.h>
@@ -63,7 +64,7 @@
6364
#endif
6465

6566
#include "common/file_perm.h"
66-
#include "libpq/pqsignal.h" /* for PG_SETMASK macro */
67+
#include "libpq/pqsignal.h"
6768
#include "pgstat.h"
6869
#include "portability/mem.h"
6970
#include "storage/dsm_impl.h"
@@ -345,6 +346,7 @@ dsm_impl_posix_resize(int fd, off_t size)
345346
{
346347
int rc;
347348
int save_errno;
349+
sigset_t save_sigmask;
348350

349351
/*
350352
* Block all blockable signals, except SIGQUIT. posix_fallocate() can run
@@ -353,7 +355,7 @@ dsm_impl_posix_resize(int fd, off_t size)
353355
* conflicts), the retry loop might never succeed.
354356
*/
355357
if (IsUnderPostmaster)
356-
PG_SETMASK(&BlockSig);
358+
sigprocmask(SIG_SETMASK, &BlockSig, &save_sigmask);
357359

358360
/* Truncate (or extend) the file to the requested size. */
359361
do
@@ -394,7 +396,7 @@ dsm_impl_posix_resize(int fd, off_t size)
394396
if (IsUnderPostmaster)
395397
{
396398
save_errno = errno;
397-
PG_SETMASK(&UnBlockSig);
399+
sigprocmask(SIG_SETMASK, &save_sigmask, NULL);
398400
errno = save_errno;
399401
}
400402

0 commit comments

Comments
 (0)