55 #include <sys/syscall.h>
71 #define SIG_PIPE_WRITE_FD master_sig_pipe[1]
72 #define SIG_PIPE_READ_FD master_sig_pipe[0]
82 static void master_sighup(
int sig)
96 static void master_sigchld(
int sig,
int code,
struct sigcontext * scp)
107 if (scp != NULL && scp->sc_syscall == SYS_select) {
108 scp->sc_syscall_action = SIG_RETURN;
110 }
else if (scp != NULL) {
111 scp->sc_syscall_action = SIG_RESTART;
120 static void master_sighup(
int sig)
122 int saved_errno = errno;
134 msg_warn(
"write to SIG_PIPE_WRITE_FD failed: %m");
140 static void master_sigchld(
int unused_sig)
142 int saved_errno = errno;
154 msg_warn(
"write to SIG_PIPE_WRITE_FD failed: %m");
160 static void master_sig_event(
int unused_event,
void *unused_context)
172 static void master_sigdeath(
int sig)
174 const char *myname =
"master_sigdeath";
175 struct sigaction action;
176 pid_t pid = getpid();
186 sigemptyset(&action.sa_mask);
188 action.sa_handler = SIG_IGN;
189 if (sigaction(SIGTERM, &action, (
struct sigaction *) 0) < 0)
191 if (kill(-pid, SIGTERM) < 0)
192 msg_fatal(
"%s: kill process group: %m", myname);
200 msg_info(
"terminating on signal %d", sig);
215 sigemptyset(&action.sa_mask);
217 action.sa_handler = SIG_DFL;
218 if (sigaction(sig, &action, (
struct sigaction *) 0) < 0)
220 if (kill(pid, sig) < 0)
221 msg_fatal(
"%s: kill myself: %m", myname);
228 const char *myname =
"master_sigsetup";
229 struct sigaction action;
230 static int sigs[] = {
231 SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGSEGV, SIGTERM,
235 sigemptyset(&action.sa_mask);
241 action.sa_handler = master_sigdeath;
242 for (i = 0; i <
sizeof(sigs) /
sizeof(sigs[0]); i++)
243 if (sigaction(sigs[i], &action, (
struct sigaction *) 0) < 0)
244 msg_fatal(
"%s: sigaction(%d): %m", myname, sigs[i]);
260 action.sa_flags |= SA_RESTART;
262 action.sa_handler = master_sighup;
263 if (sigaction(SIGHUP, &action, (
struct sigaction *) 0) < 0)
264 msg_fatal(
"%s: sigaction(%d): %m", myname, SIGHUP);
266 action.sa_flags |= SA_NOCLDSTOP;
267 action.sa_handler = master_sigchld;
268 if (sigaction(SIGCHLD, &action, (
struct sigaction *) 0) < 0)
269 msg_fatal(
"%s: sigaction(%d): %m", myname, SIGCHLD);
void event_enable_read(int fd, EVENT_NOTIFY_RDWR_FN callback, void *context)
void killme_after(unsigned int seconds)
void msg_warn(const char *fmt,...)
NORETURN msg_fatal(const char *fmt,...)
#define SIG_PIPE_WRITE_FD
int non_blocking(int, int)
void master_sigsetup(void)
int close_on_exec(int fd, int on)
void msg_info(const char *fmt,...)