From 7355e0d6d6196023abd3b8b11bfbcd645c6a17a2 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 20 Aug 2013 09:05:39 +0000 Subject: [PATCH] sighup fixes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36992 72102866-910b-0410-8b05-ffd578937521 --- EcConsole.m | 10 ++++++++-- EcProcess.m | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/EcConsole.m b/EcConsole.m index 5810c9f..b5aef2e 100644 --- a/EcConsole.m +++ b/EcConsole.m @@ -96,7 +96,13 @@ static BOOL commandIsRepeat (NSString *string) - (void) cmdQuit: (NSInteger)sig { - [ochan puts: @"\nExiting\n"]; + /* Attempt to output an exit message, but our tereminal may have gone away + * so we ignore exceptions during that. + */ + NS_DURING + [ochan puts: @"\nExiting\n"]; + NS_HANDLER + NS_ENDHANDLER #if defined(HAVE_LIBREADLINE) [self deactivateReadline]; @@ -143,7 +149,7 @@ static BOOL commandIsRepeat (NSString *string) [ochan release]; ochan = nil; } - exit(0); + [super cmdQuit: sig]; } - (void) connectionBecameInvalid: (NSNotification*)notification diff --git a/EcProcess.m b/EcProcess.m index 76d2298..0081306 100644 --- a/EcProcess.m +++ b/EcProcess.m @@ -142,7 +142,20 @@ ihandler(int sig) static RETSIGTYPE qhandler(int sig) { - signal(sig, ihandler); + if (SIGHUP == sig) + { + static int hupCount = 0; + + /* We allow multiple HUP signals since, while shutting down we may + * attempt to write out messages to our terminal, generating more + * signals, and we want to ignore those and shut down cleanly. + */ + if (hupCount++ < 1000) + { + cmdSignalled = 0; // Allow signal to be set. + } + } + /* We store the signal value in a global variable and return to normal * processing ... that way later code can check on the state of the * variable and take action outside the handler. @@ -154,19 +167,22 @@ qhandler(int sig) */ if (0 == cmdSignalled) { - cmdSignalled = sig; + cmdSignalled = sig; // Record signal for event loop. } else { static BOOL beenHere = NO; + /* We have been signalled more than once ... so let's try to + * crash rather than continuing. + */ if (NO == beenHere) { beenHere = YES; signal(SIGABRT, SIG_DFL); abort(); } - exit(sig); + exit(cmdSignalled); // Exit with *first* signal number } #if RETSIGTYPE != void return 0;