mirror of
https://github.com/postgres/postgres.git
synced 2025-09-09 13:09:39 +03:00
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
This commit is contained in:
@@ -2874,27 +2874,18 @@ setup_text_search(void)
|
|||||||
void
|
void
|
||||||
setup_signals(void)
|
setup_signals(void)
|
||||||
{
|
{
|
||||||
/* some of these are not valid on Windows */
|
|
||||||
#ifdef SIGHUP
|
|
||||||
pqsignal(SIGHUP, trapsig);
|
|
||||||
#endif
|
|
||||||
#ifdef SIGINT
|
|
||||||
pqsignal(SIGINT, trapsig);
|
pqsignal(SIGINT, trapsig);
|
||||||
#endif
|
|
||||||
#ifdef SIGQUIT
|
|
||||||
pqsignal(SIGQUIT, trapsig);
|
|
||||||
#endif
|
|
||||||
#ifdef SIGTERM
|
|
||||||
pqsignal(SIGTERM, trapsig);
|
pqsignal(SIGTERM, trapsig);
|
||||||
#endif
|
|
||||||
|
/* the following are not valid on Windows */
|
||||||
|
#ifndef WIN32
|
||||||
|
pqsignal(SIGHUP, trapsig);
|
||||||
|
pqsignal(SIGQUIT, trapsig);
|
||||||
|
|
||||||
/* Ignore SIGPIPE when writing to backend, so we can clean up */
|
/* Ignore SIGPIPE when writing to backend, so we can clean up */
|
||||||
#ifdef SIGPIPE
|
|
||||||
pqsignal(SIGPIPE, SIG_IGN);
|
pqsignal(SIGPIPE, SIG_IGN);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Prevent SIGSYS so we can probe for kernel calls that might not work */
|
/* Prevent SIGSYS so we can probe for kernel calls that might not work */
|
||||||
#ifdef SIGSYS
|
|
||||||
pqsignal(SIGSYS, SIG_IGN);
|
pqsignal(SIGSYS, SIG_IGN);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -112,11 +112,10 @@ main(int argc, char *argv[])
|
|||||||
/* Prevent leaving behind the test file */
|
/* Prevent leaving behind the test file */
|
||||||
pqsignal(SIGINT, signal_cleanup);
|
pqsignal(SIGINT, signal_cleanup);
|
||||||
pqsignal(SIGTERM, signal_cleanup);
|
pqsignal(SIGTERM, signal_cleanup);
|
||||||
|
|
||||||
|
/* the following are not valid on Windows */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
pqsignal(SIGALRM, process_alarm);
|
pqsignal(SIGALRM, process_alarm);
|
||||||
#endif
|
|
||||||
#ifdef SIGHUP
|
|
||||||
/* Not defined on win32 */
|
|
||||||
pqsignal(SIGHUP, signal_cleanup);
|
pqsignal(SIGHUP, signal_cleanup);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -518,11 +518,15 @@ make_temp_sockdir(void)
|
|||||||
* Remove the directory before dying to the usual signals. Omit SIGQUIT,
|
* Remove the directory before dying to the usual signals. Omit SIGQUIT,
|
||||||
* preserving it as a quick, untidy exit.
|
* preserving it as a quick, untidy exit.
|
||||||
*/
|
*/
|
||||||
pqsignal(SIGHUP, signal_remove_temp);
|
|
||||||
pqsignal(SIGINT, signal_remove_temp);
|
pqsignal(SIGINT, signal_remove_temp);
|
||||||
pqsignal(SIGPIPE, signal_remove_temp);
|
|
||||||
pqsignal(SIGTERM, signal_remove_temp);
|
pqsignal(SIGTERM, signal_remove_temp);
|
||||||
|
|
||||||
|
/* the following are not valid on Windows */
|
||||||
|
#ifndef WIN32
|
||||||
|
pqsignal(SIGHUP, signal_remove_temp);
|
||||||
|
pqsignal(SIGPIPE, signal_remove_temp);
|
||||||
|
#endif
|
||||||
|
|
||||||
return temp_sockdir;
|
return temp_sockdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user