Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3b8d23a

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 3a0e385 commit 3b8d23a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/storage/ipc/dsm_impl.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "postgres.h"
5050

5151
#include <fcntl.h>
52+
#include <signal.h>
5253
#include <unistd.h>
5354
#ifndef WIN32
5455
#include <sys/mman.h>
@@ -62,7 +63,7 @@
6263
#endif
6364

6465
#include "common/file_perm.h"
65-
#include "libpq/pqsignal.h" /* for PG_SETMASK macro */
66+
#include "libpq/pqsignal.h"
6667
#include "miscadmin.h"
6768
#include "pgstat.h"
6869
#include "portability/mem.h"
@@ -355,6 +356,7 @@ dsm_impl_posix_resize(int fd, off_t size)
355356
{
356357
int rc;
357358
int save_errno;
359+
sigset_t save_sigmask;
358360

359361
/*
360362
* Block all blockable signals, except SIGQUIT. posix_fallocate() can run
@@ -363,7 +365,7 @@ dsm_impl_posix_resize(int fd, off_t size)
363365
* conflicts), the retry loop might never succeed.
364366
*/
365367
if (IsUnderPostmaster)
366-
PG_SETMASK(&BlockSig);
368+
sigprocmask(SIG_SETMASK, &BlockSig, &save_sigmask);
367369

368370
pgstat_report_wait_start(WAIT_EVENT_DSM_ALLOCATE);
369371
#if defined(HAVE_POSIX_FALLOCATE) && defined(__linux__)
@@ -402,7 +404,7 @@ dsm_impl_posix_resize(int fd, off_t size)
402404
if (IsUnderPostmaster)
403405
{
404406
save_errno = errno;
405-
PG_SETMASK(&UnBlockSig);
407+
sigprocmask(SIG_SETMASK, &save_sigmask, NULL);
406408
errno = save_errno;
407409
}
408410

0 commit comments

Comments
 (0)