Cleaned up termination

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@16709 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-05-13 06:36:52 +00:00
parent ebef30d1cc
commit 3b4ac87217

View file

@ -33,6 +33,10 @@
#include "process.h" #include "process.h"
#endif #endif
#ifndef NSIG
#define NSIG 32
#endif
@class PasteboardServer; @class PasteboardServer;
@class PasteboardObject; @class PasteboardObject;
@ -926,7 +930,7 @@ NSMutableDictionary *pasteboards = nil;
if (connection == conn) if (connection == conn)
{ {
NSLog(@"Help - pasteboard server connection has died!\n"); NSLog(@"Help - pasteboard server connection has died!\n");
exit(1); exit(EXIT_FAILURE);
} }
if ([connection isKindOf: [NSConnection class]]) if ([connection isKindOf: [NSConnection class]])
{ {
@ -943,7 +947,6 @@ NSMutableDictionary *pasteboards = nil;
- (void) dealloc - (void) dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self];
RELEASE(permenant); RELEASE(permenant);
[super dealloc]; [super dealloc];
} }
@ -1015,34 +1018,54 @@ NSMutableDictionary *pasteboards = nil;
static void static void
ihandler(int sig) ihandler(int sig)
{ {
int s = 0; static BOOL beenHere = NO;
BOOL action;
/* We need to re-set ALL signals before we (try to) terminate, not const char *e;
* just the signal raised. That includes the ones we SIG_IGN.
/*
* Prevent recursion.
*/ */
for (s = 0; s < NSIG; s++) if (beenHere == YES)
signal(s, SIG_DFL);
/* Instead of abort()'ing we re-raise the original signal. Only if
* that fails, we abort().
*/
if ( sig > 0 )
{ {
#ifdef __MINGW__
abort(); abort();
#else
NSLog(@"Re-raising signal %d.", sig);
if( -1 == kill(getpid(), sig) )
{
NSLog(@"Re-raising failed, aborting.");
abort();
}
#endif
} }
beenHere = YES;
exit(EXIT_FAILURE);
/*
* If asked to terminate, do so cleanly.
*/
if (sig == SIGTERM)
{
exit(EXIT_FAILURE);
}
#ifdef DEBUG
action = YES; // abort() by default.
#else
action = NO; // exit() by default.
#endif
e = getenv("CRASH_ON_ABORT");
if (e != 0)
{
if (strcasecmp(e, "yes") == 0 || strcasecmp(e, "true") == 0)
action = YES;
else if (strcasecmp(e, "no") == 0 || strcasecmp(e, "false") == 0)
action = NO;
else if (isdigit(*e) && *e != '0')
action = YES;
else
action = NO;
}
if (action == YES)
{
abort();
}
else
{
fprintf(stderr, "gpbs killed by signal %d\n", sig);
exit(sig);
}
} }
static void static void
@ -1062,7 +1085,7 @@ init(int argc, char** argv)
printf("--help\tfor help\n"); printf("--help\tfor help\n");
printf("--no-fork\tavoid fork() to make debugging easy\n"); printf("--no-fork\tavoid fork() to make debugging easy\n");
printf("--verbose\tMore verbose debug output\n"); printf("--verbose\tMore verbose debug output\n");
exit(0); exit(EXIT_SUCCESS);
} }
else if ([a isEqualToString: @"--no-fork"] == YES) else if ([a isEqualToString: @"--no-fork"] == YES)
{ {
@ -1081,7 +1104,7 @@ init(int argc, char** argv)
printf("gpbs - GNU Pasteboard server\n"); printf("gpbs - GNU Pasteboard server\n");
printf("I don't understand '%s'\n", [a cString]); printf("I don't understand '%s'\n", [a cString]);
printf("--help for help\n"); printf("--help for help\n");
exit(0); exit(EXIT_SUCCESS);
} }
} }
@ -1118,9 +1141,9 @@ init(int argc, char** argv)
if (_spawnv(_P_NOWAIT, argv[0], a) == -1) if (_spawnv(_P_NOWAIT, argv[0], a) == -1)
{ {
fprintf(stderr, "gpbs - spawn failed - bye.\n"); fprintf(stderr, "gpbs - spawn failed - bye.\n");
exit(1); exit(EXIT_FAILURE);
} }
exit(0); exit(EXIT_SUCCESS);
} }
#else #else
switch (fork()) switch (fork())
@ -1145,7 +1168,7 @@ init(int argc, char** argv)
{ {
NSLog(@"Process backgrounded (running as daemon)\r\n"); NSLog(@"Process backgrounded (running as daemon)\r\n");
} }
exit(0); exit(EXIT_SUCCESS);
} }
#endif #endif
} }
@ -1171,7 +1194,7 @@ main(int argc, char** argv, char **env)
if (server == nil) if (server == nil)
{ {
NSLog(@"Unable to create server object.\n"); NSLog(@"Unable to create server object.\n");
exit(1); exit(EXIT_FAILURE);
} }
/* Register a connection that provides the server object to the network */ /* Register a connection that provides the server object to the network */
@ -1191,7 +1214,7 @@ main(int argc, char** argv, char **env)
if ([conn registerName: PBSNAME] == NO) if ([conn registerName: PBSNAME] == NO)
{ {
NSLog(@"Unable to register with name server.\n"); NSLog(@"Unable to register with name server.\n");
exit(1); exit(EXIT_FAILURE);
} }
} }
else else
@ -1205,7 +1228,7 @@ main(int argc, char** argv, char **env)
if (host == nil) if (host == nil)
{ {
NSLog(@"gdnc - unknown NSHost argument ... %@ - quiting.", hostname); NSLog(@"gdnc - unknown NSHost argument ... %@ - quiting.", hostname);
exit(1); exit(EXIT_FAILURE);
} }
a = [host names]; a = [host names];
c = [a count]; c = [a count];
@ -1236,9 +1259,8 @@ main(int argc, char** argv, char **env)
NSLog(@"GNU pasteboard server startup.\n"); NSLog(@"GNU pasteboard server startup.\n");
} }
[[NSRunLoop currentRunLoop] run]; [[NSRunLoop currentRunLoop] run];
RELEASE(server); RELEASE(server);
RELEASE(pool); RELEASE(pool);
exit(0); exit(EXIT_SUCCESS);
} }