Skip to content

Commit 5cda4fd

Browse files
Avoid calling pqsignal() with invalid signals on Windows frontends.
As noted by the comment at the top of port/pqsignal.c, Windows frontend programs can only use pqsignal() with the 6 signals required by C. Most places avoid using invalid signals via #ifndef WIN32, but initdb and pg_test_fsync check whether the signal itself is defined, which doesn't work because win32_port.h defines many extra signals for the signal emulation code. pg_regress seems to have missed the memo completely. These issues aren't causing any real problems today because nobody checks the return value of pqsignal(), but a follow-up commit will add some error checking. To fix, surround all frontend calls to pqsignal() that use signals that are invalid on Windows with #ifndef WIN32. We cannot simply skip defining the extra signals in win32_port.h for frontends because they are needed in places such as pgkill(). Reviewed-by: Thomas Munro Discussion: https://postgr.es/m/Z4chOKfnthRH71mw%40nathan
1 parent d7674c9 commit 5cda4fd

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/bin/initdb/initdb.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,27 +2874,18 @@ setup_text_search(void)
28742874
void
28752875
setup_signals(void)
28762876
{
2877-
/* some of these are not valid on Windows */
2878-
#ifdef SIGHUP
2879-
pqsignal(SIGHUP, trapsig);
2880-
#endif
2881-
#ifdef SIGINT
28822877
pqsignal(SIGINT, trapsig);
2883-
#endif
2884-
#ifdef SIGQUIT
2885-
pqsignal(SIGQUIT, trapsig);
2886-
#endif
2887-
#ifdef SIGTERM
28882878
pqsignal(SIGTERM, trapsig);
2889-
#endif
2879+
2880+
/* the following are not valid on Windows */
2881+
#ifndef WIN32
2882+
pqsignal(SIGHUP, trapsig);
2883+
pqsignal(SIGQUIT, trapsig);
28902884

28912885
/* Ignore SIGPIPE when writing to backend, so we can clean up */
2892-
#ifdef SIGPIPE
28932886
pqsignal(SIGPIPE, SIG_IGN);
2894-
#endif
28952887

28962888
/* Prevent SIGSYS so we can probe for kernel calls that might not work */
2897-
#ifdef SIGSYS
28982889
pqsignal(SIGSYS, SIG_IGN);
28992890
#endif
29002891
}

src/bin/pg_test_fsync/pg_test_fsync.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ main(int argc, char *argv[])
112112
/* Prevent leaving behind the test file */
113113
pqsignal(SIGINT, signal_cleanup);
114114
pqsignal(SIGTERM, signal_cleanup);
115+
116+
/* the following are not valid on Windows */
115117
#ifndef WIN32
116118
pqsignal(SIGALRM, process_alarm);
117-
#endif
118-
#ifdef SIGHUP
119-
/* Not defined on win32 */
120119
pqsignal(SIGHUP, signal_cleanup);
121120
#endif
122121

src/test/regress/pg_regress.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,15 @@ make_temp_sockdir(void)
518518
* Remove the directory before dying to the usual signals. Omit SIGQUIT,
519519
* preserving it as a quick, untidy exit.
520520
*/
521-
pqsignal(SIGHUP, signal_remove_temp);
522521
pqsignal(SIGINT, signal_remove_temp);
523-
pqsignal(SIGPIPE, signal_remove_temp);
524522
pqsignal(SIGTERM, signal_remove_temp);
525523

524+
/* the following are not valid on Windows */
525+
#ifndef WIN32
526+
pqsignal(SIGHUP, signal_remove_temp);
527+
pqsignal(SIGPIPE, signal_remove_temp);
528+
#endif
529+
526530
return temp_sockdir;
527531
}
528532

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy