/* Since orcus needed reliable signals, I decided to use my own signal function orcus_signal(); Pulled from Steven's APUE page 298 Also in this file, is all the sig handler functions. - Falcon */ /* required signel replacement for SYSV to enable reliable signals. since this works with BSD and it posix, we'll just use it instead of signal */ /* SIGSTOP and SIGKILL cannot be trapped so they are not here. */ #include "config.h" #include #include #include #include "prototypes.h" #include "show.h" void load_orcusrc(char*); int orc_quit(void); /* Captures condition of orc_quit() causing a segfault */ static int fault_fix = 0; Sigfunc * orcus_signal(int signo, Sigfunc *func) { struct sigaction act, oact; act.sa_handler = func; sigemptyset(&act.sa_mask); act.sa_flags = 0; if(signo == SIGALRM) { #ifdef SA_INTERRUPT act.sa_flags |= SA_INTERRUPT; /* SUNOS */ #endif } else { #ifdef SA_RESTART /* this is where we tell it to restart signals */ act.sa_flags |= SA_RESTART; /* SVR4 & 4.3BSD */ #endif } if(sigaction(signo, &act, &oact) < 0) return(SIG_ERR); return(oact.sa_handler); } void catch_signals(void) { extern int debug; if(orcus_signal(SIGABRT, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGABRT"); if(orcus_signal(SIGFPE, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGFPE"); if(orcus_signal(SIGCONT, sig_cont) == SIG_ERR) if(debug) perror("Can't catch SIGCONT"); if(orcus_signal(SIGHUP, sig_hup) == SIG_ERR) if(debug) perror("Can't catch SIGHUP"); if(orcus_signal(SIGILL, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGILL"); if(orcus_signal(SIGINT, sig_int) == SIG_ERR) if(debug) perror("Can't catch SIGINT"); if(orcus_signal(SIGPIPE, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGPIPE"); if(orcus_signal(SIGQUIT, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGQUIT"); if(orcus_signal(SIGSEGV, sig_segv) == SIG_ERR) if(debug) perror("Can't catch SIGSEGV"); if(orcus_signal(SIGTERM, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGTERM"); if(orcus_signal(SIGTTIN, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGTTIN"); if(orcus_signal(SIGTTOU, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGTTOU"); if(orcus_signal(SIGUSR1, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGUSR1"); if(orcus_signal(SIGUSR2, sig_default) == SIG_ERR) if(debug) perror("Can't catch SIGUSR2"); return; } static void sig_cont(int signo) /* after a ^Z, reset the term */ { extern int debug; if(debug) oprint("caught SIGCONT\n"); sttyinputset(); } static void sig_hup(int signo) /* this is for furture use */ { extern int debug; if(debug) oprint("caught SIGHUP, reloading configs.\n"); load_orcusrc(NULL); return; } static void sig_int(int signo) /* catch ^C and quit */ { extern int debug; fault_fix++; if(debug) oprint("caught SIGINT\n"); if ( fault_fix < 2 ) orc_quit(); } /* catch a SEGV, tell you about it, cleanup and quit */ static void sig_segv(int signo) { fault_fix++; oprint("caught a SEGV! Check for core!"); if ( fault_fix < 2 ) orc_quit(); } static void sig_default(int signo) /* catch all, cleanup and quit */ { extern int debug; fault_fix++; oprint("something bad has occured! caught singal %d\n", signo); if ( fault_fix < 2 ) orc_quit(); }