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

Commit 873ab97

Browse files
committed
Use SA_RESTART for all signals, including SIGALRM.
The exclusion of SIGALRM dates back to Berkeley days, when Postgres used SIGALRM in only one very short stretch of code. Nowadays, allowing it to interrupt kernel calls doesn't seem like a very good idea, since its use for statement_timeout means SIGALRM could occur anyplace in the code, and there are far too many call sites where we aren't prepared to deal with EINTR failures. When third-party code is taken into consideration, it seems impossible that we ever could be fully EINTR-proof, so better to use SA_RESTART always and deal with the implications of that. One such implication is that we should not assume pg_usleep() will be terminated early by a signal. Therefore, long sleeps should probably be replaced by WaitLatch operations where practical. Back-patch to 9.3 so we can get some beta testing on this change.
1 parent 5242fef commit 873ab97

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/backend/port/sysv_sema.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK)
405405
* it's necessary for cancel/die interrupts to be serviced directly by the
406406
* signal handler. On these platforms the behavior is really the same
407407
* whether the signal arrives just before the semop() begins, or while it
408-
* is waiting. The loop on EINTR is thus important only for other types
409-
* of interrupts.
408+
* is waiting. The loop on EINTR is thus important only for platforms
409+
* without SA_RESTART.
410410
*/
411411
do
412412
{

src/port/pqsignal.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ pqsignal(int signo, pqsigfunc func)
6060

6161
act.sa_handler = func;
6262
sigemptyset(&act.sa_mask);
63-
act.sa_flags = 0;
64-
if (signo != SIGALRM)
65-
act.sa_flags |= SA_RESTART;
63+
act.sa_flags = SA_RESTART;
6664
#ifdef SA_NOCLDSTOP
6765
if (signo == SIGCHLD)
6866
act.sa_flags |= SA_NOCLDSTOP;

0 commit comments

Comments
 (0)