]> granicus.if.org Git - postgresql/commitdiff
Use SA_RESTART for all signals, including SIGALRM.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 15 Jun 2013 19:39:51 +0000 (15:39 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 15 Jun 2013 19:40:05 +0000 (15:40 -0400)
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.

src/backend/port/sysv_sema.c
src/port/pqsignal.c

index 65f922e0230c1bdbba44c410291bd872f91261d4..2988561d0ae700311c9a0034b3bb6356f27c0969 100644 (file)
@@ -405,8 +405,8 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK)
         * it's necessary for cancel/die interrupts to be serviced directly by the
         * signal handler.      On these platforms the behavior is really the same
         * whether the signal arrives just before the semop() begins, or while it
-        * is waiting.  The loop on EINTR is thus important only for other types
-        * of interrupts.
+        * is waiting.  The loop on EINTR is thus important only for platforms
+        * without SA_RESTART.
         */
        do
        {
index 1511e932afed13bb58520826a1d973abb6f69c7d..8c82c9371c0bbed1c1bd3615edf573650922d1b7 100644 (file)
@@ -60,9 +60,7 @@ pqsignal(int signo, pqsigfunc func)
 
        act.sa_handler = func;
        sigemptyset(&act.sa_mask);
-       act.sa_flags = 0;
-       if (signo != SIGALRM)
-               act.sa_flags |= SA_RESTART;
+       act.sa_flags = SA_RESTART;
 #ifdef SA_NOCLDSTOP
        if (signo == SIGCHLD)
                act.sa_flags |= SA_NOCLDSTOP;