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

Commit c75b6b4

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 65a0cf8 commit c75b6b4

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
@@ -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"
@@ -352,6 +353,7 @@ dsm_impl_posix_resize(int fd, off_t size)
352353
{
353354
int rc;
354355
int save_errno;
356+
sigset_t save_sigmask;
355357

356358
/*
357359
* Block all blockable signals, except SIGQUIT. posix_fallocate() can run
@@ -360,7 +362,7 @@ dsm_impl_posix_resize(int fd, off_t size)
360362
* conflicts), the retry loop might never succeed.
361363
*/
362364
if (IsUnderPostmaster)
363-
PG_SETMASK(&BlockSig);
365+
sigprocmask(SIG_SETMASK, &BlockSig, &save_sigmask);
364366

365367
/* Truncate (or extend) the file to the requested size. */
366368
do
@@ -403,7 +405,7 @@ dsm_impl_posix_resize(int fd, off_t size)
403405
if (IsUnderPostmaster)
404406
{
405407
save_errno = errno;
406-
PG_SETMASK(&UnBlockSig);
408+
sigprocmask(SIG_SETMASK, &save_sigmask, NULL);
407409
errno = save_errno;
408410
}
409411

0 commit comments

Comments
 (0)