mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 08:30:59 +00:00
Tidied teermination.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16710 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a5bfb0ec52
commit
30941d3bd5
1 changed files with 62 additions and 9 deletions
|
@ -42,6 +42,10 @@
|
|||
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef NSIG
|
||||
#define NSIG 32
|
||||
#endif
|
||||
|
||||
@interface ExampleServices : NSObject
|
||||
- (void) openURL: (NSPasteboard*)bp
|
||||
userData: (NSString*)ud
|
||||
|
@ -156,11 +160,59 @@
|
|||
|
||||
static int debug = 0;
|
||||
static int verbose = 0;
|
||||
static const char *progName = "example";
|
||||
|
||||
static int
|
||||
static void
|
||||
ihandler(int sig)
|
||||
{
|
||||
abort();
|
||||
static BOOL beenHere = NO;
|
||||
BOOL action;
|
||||
const char *e;
|
||||
|
||||
/*
|
||||
* Prevent recursion.
|
||||
*/
|
||||
if (beenHere == YES)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
beenHere = YES;
|
||||
|
||||
/*
|
||||
* 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, "%s killed by signal %d\n", progName, sig);
|
||||
exit(sig);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -169,6 +221,7 @@ init(int argc, char** argv)
|
|||
const char *options = "Hdv";
|
||||
int sym;
|
||||
|
||||
progName = argv[0];
|
||||
while ((sym = getopt(argc, argv, options)) != -1)
|
||||
{
|
||||
switch(sym)
|
||||
|
@ -178,7 +231,7 @@ init(int argc, char** argv)
|
|||
printf("GNU Services example server\n");
|
||||
printf("-H\tfor help\n");
|
||||
printf("-d\tavoid fork() to make debugging easy\n");
|
||||
exit(0);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'd':
|
||||
debug++;
|
||||
|
@ -191,11 +244,11 @@ init(int argc, char** argv)
|
|||
default:
|
||||
printf("%s - GNU Pasteboard server\n", argv[0]);
|
||||
printf("-H for help\n");
|
||||
exit(0);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
for (sym = 0; sym < 32; sym++)
|
||||
for (sym = 0; sym < NSIG; sym++)
|
||||
{
|
||||
signal(sym, ihandler);
|
||||
}
|
||||
|
@ -217,7 +270,7 @@ init(int argc, char** argv)
|
|||
{
|
||||
case -1:
|
||||
NSLog(@"gpbs - fork failed - bye.\n");
|
||||
exit(1);
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
case 0:
|
||||
/*
|
||||
|
@ -235,7 +288,7 @@ init(int argc, char** argv)
|
|||
{
|
||||
NSLog(@"Process backgrounded (running as daemon)\r\n");
|
||||
}
|
||||
exit(0);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -259,14 +312,14 @@ main(int argc, char** argv, char **env)
|
|||
if (server == nil)
|
||||
{
|
||||
NSLog(@"Unable to create server object.\n");
|
||||
exit(1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
NSRegisterServicesProvider(server, @"ExampleServices");
|
||||
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
|
||||
exit(0);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue