--- master_sig.c.org Fri Jan 28 16:00:43 2000 +++ master_sig.c Sat Nov 4 15:38:42 2000 @@ -56,9 +56,18 @@ /* Local stuff. */ +#ifdef USE_SIG_PIPE +#include +#include +int master_sig_pipe[2]; +#define PIPE_WRITE_FD master_sig_pipe[1] +#define PIPE_READ_FD master_sig_pipe[0] +#endif + int master_gotsigchld; int master_gotsighup; + /* master_sighup - register arrival of hangup signal */ static void master_sighup(int sig) @@ -75,7 +84,7 @@ /* master_sigchld - register arrival of child death signal */ -#ifdef USE_SIG_RETURN +#ifdef USE_SIG_RETURN static void master_sigchld(int sig, int code, struct sigcontext * scp) { @@ -99,6 +108,29 @@ #else +#ifdef USE_SIG_PIPE +#include +static void master_sigchld(int sig) +{ + int ret; + master_gotsigchld = sig; + ret = write(PIPE_WRITE_FD, "e", 1); + if(-1 == ret) + msg_warn("write to PIPE_WRITE_FD failed with errorcode %d, %s", errno, sys_errlist[errno]); +} + +static void master_sig_event(int event, char *context) +{ + char c[1]; + int ret; + /* if(master_gotsigchld) { */ + master_gotsigchld = 0; + while (1 == read(PIPE_READ_FD, c, 1)) + ; /* Make sure we empty that (nonblocking) pipe. */ + master_reap_child(); + /* } */ +} +#else static void master_sigchld(int sig) { @@ -110,7 +142,7 @@ */ master_gotsigchld = sig; } - +#endif #endif /* master_sigdeath - die, women and children first */ @@ -162,6 +194,9 @@ SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGSEGV, SIGTERM, }; unsigned i; +#ifdef USE_SIG_PIPE + int fmode; +#endif sigemptyset(&action.sa_mask); action.sa_flags = 0; @@ -174,11 +209,21 @@ if (sigaction(sigs[i], &action, (struct sigaction *) 0) < 0) msg_fatal("%s: sigaction(%d): %m", myname, sigs[i]); +#ifdef USE_SIG_PIPE + if(pipe(master_sig_pipe)) { + msg_fatal("%s: pipe did not return 0", myname); + } + fmode = fcntl(PIPE_WRITE_FD, F_GETFL); + fmode = fcntl(PIPE_WRITE_FD, F_SETFL, fmode|O_NONBLOCK); + fmode = fcntl(PIPE_READ_FD, fmode|F_GETFL); + fmode = fcntl(PIPE_READ_FD, F_SETFL, fmode|O_NONBLOCK); + event_enable_read(PIPE_READ_FD, master_sig_event, NULL); +#endif /* * Intercept SIGHUP (re-read config file) and SIGCHLD (child exit). */ #ifdef SA_RESTART - action.sa_flags |= SA_RESTART; + action.sa_flags |= SA_RESTART; #endif action.sa_handler = master_sighup; if (sigaction(SIGHUP, &action, (struct sigaction *) 0) < 0)