0001-fix-latent-bug-in-signal-handling-per-POSIX-calling-.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From 7c0ac64ebea38d0d9ff4d160db4d33bc087a3490 Mon Sep 17 00:00:00 2001
  2. From: Robert McMahon <rjmcmahon@rjmcmahon.com>
  3. Date: Mon, 16 Jul 2018 17:51:29 -0700
  4. Subject: [PATCH] fix latent bug in signal handling, per POSIX calling exit()
  5. in signal handler is not safe. Use _exit() instead. Also, detect the user
  6. signal SIGINT for the case of server needing two invocations to stop server
  7. threads. Note: the server threads still need some work from graceful
  8. termination with a single ctrl-c
  9. ---
  10. --- a/compat/signal.c
  11. +++ b/compat/signal.c
  12. @@ -171,7 +171,7 @@ void sig_exit( int inSigno ) {
  13. static int num = 0;
  14. if ( num++ == 0 ) {
  15. fflush( 0 );
  16. - exit( 0 );
  17. + _exit(0);
  18. }
  19. } /* end sig_exit */
  20. --- a/src/main.cpp
  21. +++ b/src/main.cpp
  22. @@ -268,7 +268,7 @@ void Sig_Interupt( int inSigno ) {
  23. // We try to not allow a single interrupt handled by multiple threads
  24. // to completely kill the app so we save off the first thread ID
  25. // then that is the only thread that can supply the next interrupt
  26. - if ( thread_equalid( sThread, thread_zeroid() ) ) {
  27. + if ( (inSigno == SIGINT) && thread_equalid( sThread, thread_zeroid() ) ) {
  28. sThread = thread_getid();
  29. } else if ( thread_equalid( sThread, thread_getid() ) ) {
  30. sig_exit( inSigno );
  31. @@ -420,9 +420,3 @@ VOID ServiceStop() {
  32. }
  33. #endif
  34. -
  35. -
  36. -
  37. -
  38. -
  39. -