From: Robert McMahon <rjmcma...@rjmcmahon.com> Subject: [PATCH] fix latent bug in signal handling, per POSIX calling exit() in signal handler is not safe. Use _exit() instead. Also, detect the user signal SIGINT for the case of server needing two invocations to stop server threads. Note: the server threads still need some work from graceful termination with a single ctrl-c Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=930390 Bug-Ubuntu: https://bugs.launchpad.net/bugs/1832401 Last-Update: 2019-06-11 Applied-Upstream: https://sourceforge.net/p/iperf2/code/ci/7c0ac64ebea38d0d9ff4d160db4d33bc087a3490/
diff --git a/compat/signal.c b/compat/signal.c index 92ddc25..48a0f9d 100644 --- a/compat/signal.c +++ b/compat/signal.c @@ -171,7 +171,7 @@ void sig_exit( int inSigno ) { static int num = 0; if ( num++ == 0 ) { fflush( 0 ); - exit( 0 ); + _exit(0); } } /* end sig_exit */ diff --git a/src/main.cpp b/src/main.cpp index 53069fd..2a70e8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -268,7 +268,7 @@ void Sig_Interupt( int inSigno ) { // We try to not allow a single interrupt handled by multiple threads // to completely kill the app so we save off the first thread ID // then that is the only thread that can supply the next interrupt - if ( thread_equalid( sThread, thread_zeroid() ) ) { + if ( (inSigno == SIGINT) && thread_equalid( sThread, thread_zeroid() ) ) { sThread = thread_getid(); } else if ( thread_equalid( sThread, thread_getid() ) ) { sig_exit( inSigno ); @@ -420,9 +420,3 @@ VOID ServiceStop() { } #endif - - - - - - -- 2.20.1