aboutsummaryrefslogtreecommitdiff
path: root/src/com_start.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-05-20 10:53:30 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-05-20 10:53:30 +0300
commitddb46c6aa42ada061e51c635c0230e4dc8eab881 (patch)
treeb003ae6af354f553207981b4fc281e8f9e19c60e /src/com_start.c
parented8389beadb7cf1f8d95fe7addbc9ff2783f4d07 (diff)
downloadgenrc-ddb46c6aa42ada061e51c635c0230e4dc8eab881.tar.gz
genrc-ddb46c6aa42ada061e51c635c0230e4dc8eab881.tar.bz2
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.
Diffstat (limited to 'src/com_start.c')
-rw-r--r--src/com_start.c10
1 files changed, 7 insertions, 3 deletions
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
@@ -40,15 +40,19 @@ sigchld(int sig)
40 40
41int 41int
42timedwaitpid(pid_t pid, int *status) 42timedwaitpid(pid_t pid, int *status)
43{ 43{
44 struct timeval now, stoptime, ttw; 44 struct timeval now, stoptime, ttw;
45 int rc = -1; 45 int rc = -1;
46 SIGHANDLER oldsig; 46 struct sigaction act, oldact;
47
48 act.sa_handler = sigchld;
49 act.sa_flags = 0;
50 sigemptyset(&act.sa_mask);
51 sigaction(SIGCHLD, &act, &oldact);
47 52
48 oldsig = signal(SIGCHLD, sigchld);
49 gettimeofday(&stoptime, NULL); 53 gettimeofday(&stoptime, NULL);
50 stoptime.tv_sec += genrc_timeout; 54 stoptime.tv_sec += genrc_timeout;
51 while (1) { 55 while (1) {
52 pid_t p; 56 pid_t p;
53 57
54 p = waitpid(pid, status, WNOHANG); 58 p = waitpid(pid, status, WNOHANG);
@@ -70,13 +74,13 @@ timedwaitpid(pid_t pid, int *status)
70 system_error(errno, "select"); 74 system_error(errno, "select");
71 break; 75 break;
72 } 76 }
73 } 77 }
74 78
75 } 79 }
76 signal(SIGCHLD, oldsig); 80 sigaction(SIGCHLD, &oldact, NULL);
77 if (rc) { 81 if (rc) {
78 kill(pid, SIGKILL); 82 kill(pid, SIGKILL);
79 } 83 }
80 return rc; 84 return rc;
81} 85}
82 86

Return to:

Send suggestions and report system problems to the System administrator.