aboutsummaryrefslogtreecommitdiff
path: root/tests/server/tftpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/server/tftpd.c')
-rw-r--r--tests/server/tftpd.c128
1 files changed, 2 insertions, 126 deletions
diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c
index cac281c1e..0c94e1cb7 100644
--- a/tests/server/tftpd.c
+++ b/tests/server/tftpd.c
@@ -221,44 +221,6 @@ static sigjmp_buf timeoutbuf;
static const unsigned int rexmtval = TIMEOUT;
#endif
-/* 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 */
-
-typedef RETSIGTYPE (*SIGHANDLER_T)(int);
-
-#ifdef SIGHUP
-static SIGHANDLER_T old_sighup_handler = SIG_ERR;
-#endif
-
-#ifdef SIGPIPE
-static SIGHANDLER_T old_sigpipe_handler = SIG_ERR;
-#endif
-
-#ifdef SIGINT
-static SIGHANDLER_T old_sigint_handler = SIG_ERR;
-#endif
-
-#ifdef SIGTERM
-static SIGHANDLER_T old_sigterm_handler = SIG_ERR;
-#endif
-
-#if defined(SIGBREAK) && defined(WIN32)
-static SIGHANDLER_T old_sigbreak_handler = SIG_ERR;
-#endif
-
-/* var which if set indicates that the program should finish execution */
-
-SIG_ATOMIC_T got_exit_signal = 0;
-
-/* if next is set indicates the first signal handled in exit_signal_handler */
-
-static volatile int exit_signal = 0;
-
/*****************************************************************************
* FUNCTION PROTOTYPES *
*****************************************************************************/
@@ -295,12 +257,6 @@ static void justtimeout(int signum);
#endif /* HAVE_ALARM && SIGALRM */
-static RETSIGTYPE exit_signal_handler(int signum);
-
-static void install_signal_handlers(void);
-
-static void restore_signal_handlers(void);
-
/*****************************************************************************
* FUNCTION IMPLEMENTATIONS *
*****************************************************************************/
@@ -348,86 +304,6 @@ static void justtimeout(int signum)
#endif /* HAVE_ALARM && SIGALRM */
-/* signal handler that will be triggered to indicate that the program
- should finish its execution in a controlled manner as soon as possible.
- The first time this is called it will set got_exit_signal to one and
- store in exit_signal the signal that triggered its execution. */
-
-static RETSIGTYPE exit_signal_handler(int signum)
-{
- int old_errno = errno;
- if(got_exit_signal == 0) {
- got_exit_signal = 1;
- exit_signal = signum;
- }
- (void)signal(signum, exit_signal_handler);
- errno = old_errno;
-}
-
-static void install_signal_handlers(void)
-{
-#ifdef SIGHUP
- /* ignore SIGHUP signal */
- old_sighup_handler = signal(SIGHUP, SIG_IGN);
- if(old_sighup_handler == SIG_ERR)
- logmsg("cannot install SIGHUP handler: %s", strerror(errno));
-#endif
-#ifdef SIGPIPE
- /* ignore SIGPIPE signal */
- old_sigpipe_handler = signal(SIGPIPE, SIG_IGN);
- if(old_sigpipe_handler == SIG_ERR)
- logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
-#endif
-#ifdef SIGINT
- /* handle SIGINT signal with our exit_signal_handler */
- old_sigint_handler = signal(SIGINT, exit_signal_handler);
- if(old_sigint_handler == SIG_ERR)
- logmsg("cannot install SIGINT handler: %s", strerror(errno));
- else
- siginterrupt(SIGINT, 1);
-#endif
-#ifdef SIGTERM
- /* handle SIGTERM signal with our exit_signal_handler */
- old_sigterm_handler = signal(SIGTERM, exit_signal_handler);
- if(old_sigterm_handler == SIG_ERR)
- logmsg("cannot install SIGTERM handler: %s", strerror(errno));
- else
- siginterrupt(SIGTERM, 1);
-#endif
-#if defined(SIGBREAK) && defined(WIN32)
- /* handle SIGBREAK signal with our exit_signal_handler */
- old_sigbreak_handler = signal(SIGBREAK, exit_signal_handler);
- if(old_sigbreak_handler == SIG_ERR)
- logmsg("cannot install SIGBREAK handler: %s", strerror(errno));
- else
- siginterrupt(SIGBREAK, 1);
-#endif
-}
-
-static void restore_signal_handlers(void)
-{
-#ifdef SIGHUP
- if(SIG_ERR != old_sighup_handler)
- (void)signal(SIGHUP, old_sighup_handler);
-#endif
-#ifdef SIGPIPE
- if(SIG_ERR != old_sigpipe_handler)
- (void)signal(SIGPIPE, old_sigpipe_handler);
-#endif
-#ifdef SIGINT
- if(SIG_ERR != old_sigint_handler)
- (void)signal(SIGINT, old_sigint_handler);
-#endif
-#ifdef SIGTERM
- if(SIG_ERR != old_sigterm_handler)
- (void)signal(SIGTERM, old_sigterm_handler);
-#endif
-#if defined(SIGBREAK) && defined(WIN32)
- if(SIG_ERR != old_sigbreak_handler)
- (void)signal(SIGBREAK, old_sigbreak_handler);
-#endif
-}
-
/*
* init for either read-ahead or write-behind.
* zero for write-behind, one for read-head.
@@ -757,7 +633,7 @@ int main(int argc, char **argv)
atexit(win32_cleanup);
#endif
- install_signal_handlers();
+ install_signal_handlers(true);
pid = (long)getpid();
@@ -930,7 +806,7 @@ tftpd_cleanup:
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
- restore_signal_handlers();
+ restore_signal_handlers(true);
if(got_exit_signal) {
logmsg("========> %s tftpd (port: %d pid: %ld) exits with signal (%d)",