1
0
mirror of https://github.com/moparisthebest/curl synced 2025-01-10 21:48:10 -05:00

test server: take care of siginterrupt() deprecation

Closes #6529
This commit is contained in:
Patrick Monnerat 2021-01-26 03:10:48 +01:00 committed by Daniel Stenberg
parent 2df64390b3
commit 3fb6e5a010
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -535,12 +535,6 @@ long timediff(struct timeval newer, struct timeval older)
(long)(newer.tv_usec-older.tv_usec)/1000; (long)(newer.tv_usec-older.tv_usec)/1000;
} }
/* do-nothing macro replacement for systems which lack siginterrupt() */
#ifndef HAVE_SIGINTERRUPT
#define siginterrupt(x,y) do {} while(0)
#endif
/* vars used to keep around previous signal handlers */ /* vars used to keep around previous signal handlers */
typedef void (*SIGHANDLER_T)(int); typedef void (*SIGHANDLER_T)(int);
@ -721,6 +715,36 @@ static DWORD WINAPI main_window_loop(LPVOID lpParameter)
} }
#endif #endif
static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler,
bool restartable)
{
#if defined(HAVE_SIGACTION) && defined(SA_RESTART)
struct sigaction sa, oldsa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, signum);
sa.sa_flags = restartable? SA_RESTART: 0;
if(sigaction(signum, &sa, &oldsa))
return SIG_ERR;
return oldsa.sa_handler;
#else
SIGHANDLER_T oldhdlr = signal(signum, handler);
#ifdef HAVE_SIGINTERRUPT
if(oldhdlr != SIG_ERR)
siginterrupt(signum, (int) restartable);
#else
(void) restartable;
#endif
return oldhdlr;
#endif
}
void install_signal_handlers(bool keep_sigalrm) void install_signal_handlers(bool keep_sigalrm)
{ {
#ifdef WIN32 #ifdef WIN32
@ -731,20 +755,20 @@ void install_signal_handlers(bool keep_sigalrm)
#endif #endif
#ifdef SIGHUP #ifdef SIGHUP
/* ignore SIGHUP signal */ /* ignore SIGHUP signal */
old_sighup_handler = signal(SIGHUP, SIG_IGN); old_sighup_handler = set_signal(SIGHUP, SIG_IGN, FALSE);
if(old_sighup_handler == SIG_ERR) if(old_sighup_handler == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(errno)); logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
/* ignore SIGPIPE signal */ /* ignore SIGPIPE signal */
old_sigpipe_handler = signal(SIGPIPE, SIG_IGN); old_sigpipe_handler = set_signal(SIGPIPE, SIG_IGN, FALSE);
if(old_sigpipe_handler == SIG_ERR) if(old_sigpipe_handler == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(errno)); logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif #endif
#ifdef SIGALRM #ifdef SIGALRM
if(!keep_sigalrm) { if(!keep_sigalrm) {
/* ignore SIGALRM signal */ /* ignore SIGALRM signal */
old_sigalrm_handler = signal(SIGALRM, SIG_IGN); old_sigalrm_handler = set_signal(SIGALRM, SIG_IGN, FALSE);
if(old_sigalrm_handler == SIG_ERR) if(old_sigalrm_handler == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(errno)); logmsg("cannot install SIGALRM handler: %s", strerror(errno));
} }
@ -753,27 +777,21 @@ void install_signal_handlers(bool keep_sigalrm)
#endif #endif
#ifdef SIGINT #ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */ /* handle SIGINT signal with our exit_signal_handler */
old_sigint_handler = signal(SIGINT, exit_signal_handler); old_sigint_handler = set_signal(SIGINT, exit_signal_handler, TRUE);
if(old_sigint_handler == SIG_ERR) if(old_sigint_handler == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(errno)); logmsg("cannot install SIGINT handler: %s", strerror(errno));
else
siginterrupt(SIGINT, 1);
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */ /* handle SIGTERM signal with our exit_signal_handler */
old_sigterm_handler = signal(SIGTERM, exit_signal_handler); old_sigterm_handler = set_signal(SIGTERM, exit_signal_handler, TRUE);
if(old_sigterm_handler == SIG_ERR) if(old_sigterm_handler == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(errno)); logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else
siginterrupt(SIGTERM, 1);
#endif #endif
#if defined(SIGBREAK) && defined(WIN32) #if defined(SIGBREAK) && defined(WIN32)
/* handle SIGBREAK signal with our exit_signal_handler */ /* handle SIGBREAK signal with our exit_signal_handler */
old_sigbreak_handler = signal(SIGBREAK, exit_signal_handler); old_sigbreak_handler = set_signal(SIGBREAK, exit_signal_handler, TRUE);
if(old_sigbreak_handler == SIG_ERR) if(old_sigbreak_handler == SIG_ERR)
logmsg("cannot install SIGBREAK handler: %s", strerror(errno)); logmsg("cannot install SIGBREAK handler: %s", strerror(errno));
else
siginterrupt(SIGBREAK, 1);
#endif #endif
#ifdef WIN32 #ifdef WIN32
if(!SetConsoleCtrlHandler(ctrl_event_handler, TRUE)) if(!SetConsoleCtrlHandler(ctrl_event_handler, TRUE))
@ -791,31 +809,31 @@ void restore_signal_handlers(bool keep_sigalrm)
{ {
#ifdef SIGHUP #ifdef SIGHUP
if(SIG_ERR != old_sighup_handler) if(SIG_ERR != old_sighup_handler)
(void)signal(SIGHUP, old_sighup_handler); (void) set_signal(SIGHUP, old_sighup_handler, FALSE);
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
if(SIG_ERR != old_sigpipe_handler) if(SIG_ERR != old_sigpipe_handler)
(void)signal(SIGPIPE, old_sigpipe_handler); (void) set_signal(SIGPIPE, old_sigpipe_handler, FALSE);
#endif #endif
#ifdef SIGALRM #ifdef SIGALRM
if(!keep_sigalrm) { if(!keep_sigalrm) {
if(SIG_ERR != old_sigalrm_handler) if(SIG_ERR != old_sigalrm_handler)
(void)signal(SIGALRM, old_sigalrm_handler); (void) set_signal(SIGALRM, old_sigalrm_handler, FALSE);
} }
#else #else
(void)keep_sigalrm; (void)keep_sigalrm;
#endif #endif
#ifdef SIGINT #ifdef SIGINT
if(SIG_ERR != old_sigint_handler) if(SIG_ERR != old_sigint_handler)
(void)signal(SIGINT, old_sigint_handler); (void) set_signal(SIGINT, old_sigint_handler, FALSE);
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
if(SIG_ERR != old_sigterm_handler) if(SIG_ERR != old_sigterm_handler)
(void)signal(SIGTERM, old_sigterm_handler); (void) set_signal(SIGTERM, old_sigterm_handler, FALSE);
#endif #endif
#if defined(SIGBREAK) && defined(WIN32) #if defined(SIGBREAK) && defined(WIN32)
if(SIG_ERR != old_sigbreak_handler) if(SIG_ERR != old_sigbreak_handler)
(void)signal(SIGBREAK, old_sigbreak_handler); (void) set_signal(SIGBREAK, old_sigbreak_handler, FALSE);
#endif #endif
#ifdef WIN32 #ifdef WIN32
(void)SetConsoleCtrlHandler(ctrl_event_handler, FALSE); (void)SetConsoleCtrlHandler(ctrl_event_handler, FALSE);