mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Provide sigaction() for Windows.
Commit9abb2bfcleft behind code to block signals inside signal handlers on Windows, because our signal porting layer didn't have sigaction(). Provide a minimal implementation that is capable of blocking signals, to get rid of platform differences. See also related commitc94ae9d8. Discussion: https://postgr.es/m/CA%2BhUKGKKKfcgx6jzok9AYenp2TNti_tfs8FMoJpL8%2B0Gsy%3D%3D_A%40mail.gmail.com
This commit is contained in:
@@ -620,10 +620,10 @@ PostmasterMain(int argc, char *argv[])
|
||||
* is used by all child processes and client processes). That has a
|
||||
* couple of special behaviors:
|
||||
*
|
||||
* 1. Except on Windows, we tell sigaction() to block all signals for the
|
||||
* duration of the signal handler. This is faster than our old approach
|
||||
* of blocking/unblocking explicitly in the signal handler, and it should
|
||||
* also prevent excessive stack consumption if signals arrive quickly.
|
||||
* 1. We tell sigaction() to block all signals for the duration of the
|
||||
* signal handler. This is faster than our old approach of
|
||||
* blocking/unblocking explicitly in the signal handler, and it should also
|
||||
* prevent excessive stack consumption if signals arrive quickly.
|
||||
*
|
||||
* 2. We do not set the SA_RESTART flag. This is because signals will be
|
||||
* blocked at all times except when ServerLoop is waiting for something to
|
||||
@@ -2726,14 +2726,6 @@ SIGHUP_handler(SIGNAL_ARGS)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
/*
|
||||
* We rely on the signal mechanism to have blocked all signals ... except
|
||||
* on Windows, which lacks sigaction(), so we have to do it manually.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&BlockSig);
|
||||
#endif
|
||||
|
||||
if (Shutdown <= SmartShutdown)
|
||||
{
|
||||
ereport(LOG,
|
||||
@@ -2790,10 +2782,6 @@ SIGHUP_handler(SIGNAL_ARGS)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&UnBlockSig);
|
||||
#endif
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
@@ -2806,14 +2794,6 @@ pmdie(SIGNAL_ARGS)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
/*
|
||||
* We rely on the signal mechanism to have blocked all signals ... except
|
||||
* on Windows, which lacks sigaction(), so we have to do it manually.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&BlockSig);
|
||||
#endif
|
||||
|
||||
ereport(DEBUG2,
|
||||
(errmsg_internal("postmaster received signal %d",
|
||||
postgres_signal_arg)));
|
||||
@@ -2938,10 +2918,6 @@ pmdie(SIGNAL_ARGS)
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&UnBlockSig);
|
||||
#endif
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
@@ -2955,14 +2931,6 @@ reaper(SIGNAL_ARGS)
|
||||
int pid; /* process id of dead child process */
|
||||
int exitstatus; /* its exit status */
|
||||
|
||||
/*
|
||||
* We rely on the signal mechanism to have blocked all signals ... except
|
||||
* on Windows, which lacks sigaction(), so we have to do it manually.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&BlockSig);
|
||||
#endif
|
||||
|
||||
ereport(DEBUG4,
|
||||
(errmsg_internal("reaping dead processes")));
|
||||
|
||||
@@ -3255,11 +3223,6 @@ reaper(SIGNAL_ARGS)
|
||||
*/
|
||||
PostmasterStateMachine();
|
||||
|
||||
/* Done with signal handler */
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&UnBlockSig);
|
||||
#endif
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
@@ -5106,14 +5069,6 @@ sigusr1_handler(SIGNAL_ARGS)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
/*
|
||||
* We rely on the signal mechanism to have blocked all signals ... except
|
||||
* on Windows, which lacks sigaction(), so we have to do it manually.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&BlockSig);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* RECOVERY_STARTED and BEGIN_HOT_STANDBY signals are ignored in
|
||||
* unexpected states. If the startup process quickly starts up, completes
|
||||
@@ -5254,10 +5209,6 @@ sigusr1_handler(SIGNAL_ARGS)
|
||||
signal_child(StartupPID, SIGUSR2);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
PG_SETMASK(&UnBlockSig);
|
||||
#endif
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user