#include #include #include /* ** never core dump. */ /* * Signals that cause a core dump * * SIGQUIT 3 Core Quit (see termio(7I)) * SIGILL 4 Core Illegal Instruction * SIGTRAP 5 Core Trace/Breakpoint Trap * SIGABRT 6 Core Abort * SIGEMT 7 Core Emulation Trap * SIGFPE 8 Core Arithmetic Exception * SIGBUS 10 Core Bus Error * SIGSEGV 11 Core Segmentation Fault * SIGSYS 12 Core Bad System Call * SIGXCPU 30 Core CPU time limit exceeded (see getrlimit(2)) * SIGXFSZ 31 Core File size limit exceeded (see getrlimit(2)) */ static void noCoredump(void) { #ifdef SIGQUIT signal(SIGQUIT, SIG_IGN ); #endif /* SIGQUIT */ #ifdef SIGILL signal(SIGILL, SIG_IGN ); #endif /* SIGILL */ #ifdef SIGTRAP signal(SIGTRAP, SIG_IGN ); #endif /* SIGTRAP */ #ifdef SIGABRT signal(SIGABRT, SIG_IGN ); #endif /* SIGABRT */ #ifdef SIGEMT signal(SIGEMT, SIG_IGN ); #endif /* SIGEMT */ #ifdef SIGFPE signal(SIGFPE, SIG_IGN ); #endif /* SIGFPE */ #ifdef SIGBUS signal(SIGBUS, SIG_IGN ); #endif /* SIGBUS */ #ifdef SIGSEGV signal(SIGSEGV, SIG_IGN ); #endif /* SIGSEGV */ #ifdef SIGSYS signal(SIGSYS, SIG_IGN ); #endif /* SIGSYS */ #ifdef SIGXCPU signal(SIGXCPU, SIG_IGN ); #endif /* SIGXCPU */ #ifdef SIGXFSZ signal(SIGXFSZ, SIG_IGN ); #endif /* SIGXFSZ */ } static void daemonize(void) { int i; if (fork()) { _exit(0); /* parent goes bye-bye */ } /* ** detach from terminal */ #ifdef HAVE_SETSID setsid(); /* request a new session */ #else #ifdef TIOCNOTTY i=open("/dev/tty",O_RDWR); if (i >= 0) { ioctl(i, (int)TIOCNOTTY, (char *)NULL); close(i); } #endif /* TIO CNOTTY */ #endif /* HAVE_SETSID */ chdir("/"); umask(0); } /* ** duplicate a string */ static char *mystrdup (char *string) { char *tmp; if (string == (char *) NULL) return ((char *) NULL); tmp = (char *) malloc ((int) strlen(string) + 1); if (tmp == (char *) NULL) { perror("memory allocation problem mystrdup()"); exit(0); } /* it's safe to copy this way */ (void) strcpy(tmp,string); tmp[strlen(tmp)+1]='\0'; return (tmp); }