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

Commit 3c07fbf

Browse files
committed
Use pqsignal() in contrib programs rather than calling signal(2) directly.
The semantics of signal(2) are more variable than one could wish; in particular, on strict-POSIX platforms the signal handler will be reset to SIG_DFL when the signal is delivered. This demonstrably breaks pg_test_fsync's use of SIGALRM. The other changes I made are not absolutely necessary today, because the called handlers all exit the program anyway. But it seems like a good general practice to use pqsignal() exclusively in Postgres code, now that we have it available everywhere.
1 parent b1fae82 commit 3c07fbf

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

contrib/pg_standby/pg_standby.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ sighandler(int sig)
549549
static void
550550
sigquit_handler(int sig)
551551
{
552-
signal(SIGINT, SIG_DFL);
552+
pqsignal(SIGINT, SIG_DFL);
553553
kill(getpid(), SIGINT);
554554
}
555555
#endif
@@ -592,9 +592,9 @@ main(int argc, char **argv)
592592
*
593593
* There's no way to trigger failover via signal on Windows.
594594
*/
595-
(void) signal(SIGUSR1, sighandler);
596-
(void) signal(SIGINT, sighandler); /* deprecated, use SIGUSR1 */
597-
(void) signal(SIGQUIT, sigquit_handler);
595+
(void) pqsignal(SIGUSR1, sighandler);
596+
(void) pqsignal(SIGINT, sighandler); /* deprecated, use SIGUSR1 */
597+
(void) pqsignal(SIGQUIT, sigquit_handler);
598598
#endif
599599

600600
while ((c = getopt(argc, argv, "cdk:lr:s:t:w:")) != -1)

contrib/pg_test_fsync/pg_test_fsync.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ main(int argc, char *argv[])
101101
handle_args(argc, argv);
102102

103103
/* Prevent leaving behind the test file */
104-
signal(SIGINT, signal_cleanup);
105-
signal(SIGTERM, signal_cleanup);
104+
pqsignal(SIGINT, signal_cleanup);
105+
pqsignal(SIGTERM, signal_cleanup);
106106
#ifndef WIN32
107-
signal(SIGALRM, process_alarm);
107+
pqsignal(SIGALRM, process_alarm);
108108
#endif
109109
#ifdef SIGHUP
110110
/* Not defined on win32 */
111-
signal(SIGHUP, signal_cleanup);
111+
pqsignal(SIGHUP, signal_cleanup);
112112
#endif
113113

114114
prepare_buf();

0 commit comments

Comments
 (0)