#include "config.h" #if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT) #include #endif #include "common.h" #include "sig.h" extern "C" { int caught_sig_type = 0; #ifdef HAVE_WAITPID #define WAIT_NOHANG(status) waitpid (-1, (status), WNOHANG) #else /* Don't have waitpid. */ #ifdef HAVE_WAIT3 #ifndef wait3 extern int wait3 (); #endif #define WAIT_NOHANG(status) wait3 ((status), WNOHANG, (struct rusage *) 0) #endif /* Have wait3. */ #endif /* Have waitpid. */ void reset_sig() { caught_sig_type = 0; } void sig_int() { if (!caught_sig_type) { caught_sig_type = SIGINT; } PUTERR(2, ("caught SIGINT\n")); } void sig_child() { caught_sig_type = SIGCHLD; PUTERR(2, ("caught SIGCHLD, delete zonbie process()\n")); while ( WAIT_NOHANG(0) > 0); } void sig_cont() { if (!caught_sig_type) { caught_sig_type = SIGCONT; } PUTERR(2, ("caught SIGCONT\n")); } void sig_usr1() { caught_sig_type = SIGUSR1; PUTERR(2, ("caught SIGUSR1\n")); } void sig_usr2() { caught_sig_type = SIGUSR2; PUTERR(2, ("caught SIGUSR1\n")); } void sig_hup() { caught_sig_type = SIGHUP; PUTERR(1, ("caught SIGHUP\n")); } void sig_term() { caught_sig_type = SIGTERM; PUTERR(2, ("caught SIGTERM\n")); } void sig_tstp() { caught_sig_type = SIGTSTP; PUTERR(2, ("caught SIGTSTP\n")); } DEFFUNC_SIG(SIGHUP , sig_hup); DEFFUNC_SIG(SIGINT , sig_int); DEFFUNC_SIG(SIGCHLD, sig_child); DEFFUNC_SIG(SIGCONT, sig_cont); DEFFUNC_SIG(SIGUSR1, sig_usr1); DEFFUNC_SIG(SIGUSR2, sig_usr2); DEFFUNC_SIG(SIGTERM, sig_term); DEFFUNC_SIG(SIGTSTP, sig_tstp); int get_caught_sig_type() { int ret = caught_sig_type; reset_sig(); return ret; } void set_caught_sig_type(int n) { caught_sig_type =n; } void terminate_all_process() { signal(SIGUSR1, SIG_IGN); kill(0, SIGUSR1); } } /* extern "C" */