From ddb46c6aa42ada061e51c635c0230e4dc8eab881 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sun, 20 May 2018 10:53:30 +0300 Subject: Sentinel mode: restart the program on certain conditions * Makefile.am: Create the ChangeLog file from git log. * configure.ac: Request git2chg * src/com_start.c: Use sigaction instead of signal. * src/genrc.8: Document new options. * src/genrc.c: New options --restart-on-exit and --restart-on-signal. * src/genrc.h (str_to_sig, str_to_int): New prototypes. (add_restart_condition): New prototype. * src/sentinel.c (restart_on, add_restart_condition): (check_failure_rate): New functions. (wait_loop): Return if restart is requested. (sentinel): Restart the program if needed. --- src/com_start.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/com_start.c') diff --git a/src/com_start.c b/src/com_start.c index 5744e39..3a9dffc 100644 --- a/src/com_start.c +++ b/src/com_start.c @@ -43,9 +43,13 @@ timedwaitpid(pid_t pid, int *status) { struct timeval now, stoptime, ttw; int rc = -1; - SIGHANDLER oldsig; - - oldsig = signal(SIGCHLD, sigchld); + struct sigaction act, oldact; + + act.sa_handler = sigchld; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGCHLD, &act, &oldact); + gettimeofday(&stoptime, NULL); stoptime.tv_sec += genrc_timeout; while (1) { @@ -73,7 +77,7 @@ timedwaitpid(pid_t pid, int *status) } } - signal(SIGCHLD, oldsig); + sigaction(SIGCHLD, &oldact, NULL); if (rc) { kill(pid, SIGKILL); } -- cgit v1.2.1