mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-28 00:47:19 +02:00
Make dsm_impl_posix_resize more future-proof.
Commit4518c798
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 commita65e0864
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, like4518c798
and80845b7c
. 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
This commit is contained in:
parent
27b8f73fd3
commit
1661c40b9d
@ -50,6 +50,7 @@
|
|||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@ -63,7 +64,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common/file_perm.h"
|
#include "common/file_perm.h"
|
||||||
#include "libpq/pqsignal.h" /* for PG_SETMASK macro */
|
#include "libpq/pqsignal.h"
|
||||||
#include "pgstat.h"
|
#include "pgstat.h"
|
||||||
#include "portability/mem.h"
|
#include "portability/mem.h"
|
||||||
#include "storage/dsm_impl.h"
|
#include "storage/dsm_impl.h"
|
||||||
@ -345,6 +346,7 @@ dsm_impl_posix_resize(int fd, off_t size)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int save_errno;
|
int save_errno;
|
||||||
|
sigset_t save_sigmask;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Block all blockable signals, except SIGQUIT. posix_fallocate() can run
|
* Block all blockable signals, except SIGQUIT. posix_fallocate() can run
|
||||||
@ -353,7 +355,7 @@ dsm_impl_posix_resize(int fd, off_t size)
|
|||||||
* conflicts), the retry loop might never succeed.
|
* conflicts), the retry loop might never succeed.
|
||||||
*/
|
*/
|
||||||
if (IsUnderPostmaster)
|
if (IsUnderPostmaster)
|
||||||
PG_SETMASK(&BlockSig);
|
sigprocmask(SIG_SETMASK, &BlockSig, &save_sigmask);
|
||||||
|
|
||||||
/* Truncate (or extend) the file to the requested size. */
|
/* Truncate (or extend) the file to the requested size. */
|
||||||
do
|
do
|
||||||
@ -394,7 +396,7 @@ dsm_impl_posix_resize(int fd, off_t size)
|
|||||||
if (IsUnderPostmaster)
|
if (IsUnderPostmaster)
|
||||||
{
|
{
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
PG_SETMASK(&UnBlockSig);
|
sigprocmask(SIG_SETMASK, &save_sigmask, NULL);
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user