sighup fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36992 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-08-20 09:05:39 +00:00
parent b712815435
commit 7355e0d6d6
2 changed files with 27 additions and 5 deletions

View file

@ -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

View file

@ -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;