aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am11
-rw-r--r--configure.ac4
-rw-r--r--src/com_start.c10
-rw-r--r--src/genrc.858
-rw-r--r--src/genrc.c41
-rw-r--r--src/genrc.h10
-rw-r--r--src/sentinel.c190
7 files changed, 304 insertions, 20 deletions
diff --git a/Makefile.am b/Makefile.am
index 31e9e5f..dac3cb3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1,12 @@
1SUBDIRS = grecs src 1SUBDIRS = grecs src
2dist: ChangeLog
3.PHONY: ChangeLog
4ChangeLog:
5 $(AM_V_GEN)if test -d .git; then \
6 git log --pretty='format:%ct %an <%ae>%n%n%s%n%n%b%n' | \
7 awk -f $(top_srcdir)/@GRECS_SUBDIR@/build-aux/git2chg.awk \
8 > ChangeLog.tmp; \
9 cmp ChangeLog ChangeLog.tmp > /dev/null 2>&1 || \
10 mv ChangeLog.tmp ChangeLog; \
11 rm -f ChangeLog.tmp; \
12 fi
diff --git a/configure.ac b/configure.ac
index 5d36092..a568649 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,47 +6,47 @@
6# the Free Software Foundation; either version 3, or (at your option) 6# the Free Software Foundation; either version 3, or (at your option)
7# any later version. 7# any later version.
8# 8#
9# Genrc is distributed in the hope that it will be useful, 9# Genrc is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details. 12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with genrc. If not, see <http://www.gnu.org/licenses/>. 15# along with genrc. If not, see <http://www.gnu.org/licenses/>.
16 16
17AC_PREREQ([2.69]) 17AC_PREREQ([2.69])
18AC_INIT([genrc], [1.0], [gray@gnu.org]) 18AC_INIT([genrc], [1.0.90], [gray@gnu.org])
19AC_CONFIG_SRCDIR([src/genrc.c]) 19AC_CONFIG_SRCDIR([src/genrc.c])
20AC_CONFIG_HEADERS([config.h]) 20AC_CONFIG_HEADERS([config.h])
21AM_INIT_AUTOMAKE([1.11 foreign silent-rules]) 21AM_INIT_AUTOMAKE([1.11 foreign silent-rules])
22AC_CONFIG_MACRO_DIR(grecs/am) 22AC_CONFIG_MACRO_DIR(grecs/am)
23 23
24# Enable silent rules by default 24# Enable silent rules by default
25AM_SILENT_RULES([yes]) 25AM_SILENT_RULES([yes])
26 26
27# Checks for programs. 27# Checks for programs.
28AC_PROG_CC 28AC_PROG_CC
29AC_PROG_RANLIB 29AC_PROG_RANLIB
30 30
31# Checks for libraries. 31# Checks for libraries.
32AC_CHECK_LIB(pcre, main) 32AC_CHECK_LIB(pcre, main)
33 33
34# Checks for header files. 34# Checks for header files.
35AC_CHECK_HEADERS([getopt.h pcre.h]) 35AC_CHECK_HEADERS([getopt.h pcre.h])
36 36
37# Checks for library functions. 37# Checks for library functions.
38AC_CHECK_FUNCS([getdtablesize]) 38AC_CHECK_FUNCS([getdtablesize])
39 39
40GRECS_SETUP(grecs, [all-parsers]) 40GRECS_SETUP(grecs, [all-parsers git2chg])
41 41
42AM_CONDITIONAL([COND_PCRE], 42AM_CONDITIONAL([COND_PCRE],
43 [test "$ac_cv_header_pcre_h" = yes && test "$ac_cv_lib_pcre_main" = yes]) 43 [test "$ac_cv_header_pcre_h" = yes && test "$ac_cv_lib_pcre_main" = yes])
44 44
45if test -f /proc/$$/cmdline; then 45if test -f /proc/$$/cmdline; then
46 DEFAULT_PID_SOURCE='"PROC"' 46 DEFAULT_PID_SOURCE='"PROC"'
47else 47else
48 DEFAULT_PID_SOURCE='"PS"' 48 DEFAULT_PID_SOURCE='"PS"'
49fi 49fi
50AC_DEFINE_UNQUOTED(DEFAULT_PID_SOURCE,$DEFAULT_PID_SOURCE, 50AC_DEFINE_UNQUOTED(DEFAULT_PID_SOURCE,$DEFAULT_PID_SOURCE,
51 [Default PID source]) 51 [Default PID source])
52 52
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
@@ -34,27 +34,31 @@ report_exec_error(int rc, char const *program)
34typedef void (*SIGHANDLER)(int); 34typedef void (*SIGHANDLER)(int);
35 35
36void 36void
37sigchld(int sig) 37sigchld(int sig)
38{ 38{
39} 39}
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);
55 if (p == pid) { 59 if (p == pid) {
56 rc = 0; 60 rc = 0;
57 break; 61 break;
58 } 62 }
59 if (p < 0 && errno != EINTR) { 63 if (p < 0 && errno != EINTR) {
60 system_error(errno, "waitpid"); 64 system_error(errno, "waitpid");
@@ -64,25 +68,25 @@ timedwaitpid(pid_t pid, int *status)
64 gettimeofday(&now, NULL); 68 gettimeofday(&now, NULL);
65 if (timercmp(&now, &stoptime, >=)) 69 if (timercmp(&now, &stoptime, >=))
66 break; 70 break;
67 timersub(&stoptime, &now, &ttw); 71 timersub(&stoptime, &now, &ttw);
68 if (select(0, NULL, NULL, NULL, &ttw) < 0) { 72 if (select(0, NULL, NULL, NULL, &ttw) < 0) {
69 if (errno != EINTR) { 73 if (errno != EINTR) {
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
83int 87int
84com_start(void) 88com_start(void)
85{ 89{
86 pid_t pid; 90 pid_t pid;
87 int status; 91 int status;
88 PIDLIST pids; 92 PIDLIST pids;
diff --git a/src/genrc.8 b/src/genrc.8
index 00522ee..959a00e 100644
--- a/src/genrc.8
+++ b/src/genrc.8
@@ -4,47 +4,49 @@
4.\" Genrc is free software; you can redistribute it and/or modify 4.\" Genrc is free software; you can redistribute it and/or modify
5.\" it under the terms of the GNU General Public License as published by 5.\" it under the terms of the GNU General Public License as published by
6.\" the Free Software Foundation; either version 3, or (at your option) 6.\" the Free Software Foundation; either version 3, or (at your option)
7.\" any later version. 7.\" any later version.
8.\" 8.\"
9.\" Genrc is distributed in the hope that it will be useful, 9.\" Genrc is distributed in the hope that it will be useful,
10.\" but WITHOUT ANY WARRANTY; without even the implied warranty of 10.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
11.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12.\" GNU General Public License for more details. 12.\" GNU General Public License for more details.
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with genrc. If not, see <http://www.gnu.org/licenses/>. 15.\" along with genrc. If not, see <http://www.gnu.org/licenses/>.
16.TH GENRC 8 "May 17, 2018" "GENRC" "Genrc User Manual" 16.TH GENRC 8 "May 20, 2018" "GENRC" "Genrc User Manual"
17.SH NAME 17.SH NAME
18genrc \- generic system initialization script helper 18genrc \- generic system initialization script helper
19.SH SYNOPSIS 19.SH SYNOPSIS
20.nh 20.nh
21.na 21.na
22\fBgenrc\fR\ 22\fBgenrc\fR\
23 [\fB\-hv\fR]\ 23 [\fB\-hv\fR]\
24 [\fB\-F\fR \fIPIDFILE\fR]\ 24 [\fB\-F\fR \fIPIDFILE\fR]\
25 [\fB\-P\fR \fISOURCE\fR]\ 25 [\fB\-P\fR \fISOURCE\fR]\
26 [\fB\-c\fR \fICOMMAND\fR]\ 26 [\fB\-c\fR \fICOMMAND\fR]\
27 [\fB\-g\fR \fIGROUP\fR[,\fIGROUP\fR...]]\ 27 [\fB\-g\fR \fIGROUP\fR[,\fIGROUP\fR...]]\
28 [\fB\-p\fR \fIPROGRAM\fR]\ 28 [\fB\-p\fR \fIPROGRAM\fR]\
29 [\fB\-t\fR \fISECONDS\fR]\ 29 [\fB\-t\fR \fISECONDS\fR]\
30 [\fB\-u\fR \fIUSER\fR]\ 30 [\fB\-u\fR \fIUSER\fR]\
31 [\fB\-\-command=\fICOMMAND\fR]\ 31 [\fB\-\-command=\fICOMMAND\fR]\
32 [\fB\-\-create\-pidfile=\fIPIDFILE\fR]\ 32 [\fB\-\-create\-pidfile=\fIPIDFILE\fR]\
33 [\fB\-\-group=\fIGROUP\fR[,\fIGROUP\fR...]]\ 33 [\fB\-\-group=\fIGROUP\fR[,\fIGROUP\fR...]]\
34 [\fB\-\-help\fR]\ 34 [\fB\-\-help\fR]\
35 [\fB\-\-no\-reload\fR]\ 35 [\fB\-\-no\-reload\fR]\
36 [\fB\-\-pid\-from=\fISOURCE\fR]\ 36 [\fB\-\-pid\-from=\fISOURCE\fR]\
37 [\fB\-\-pidfile=\fIPIDFILE\fR]\ 37 [\fB\-\-pidfile=\fIPIDFILE\fR]\
38 [\fB\-\-program=\fIPROGRAM\fR]\ 38 [\fB\-\-program=\fIPROGRAM\fR]\
39 [\fB\-\-restart\-on\-exit=\fR[\fB!\fR]\fISTATUS\fR[\fB,\fISTATUS\fR...]]\
40 [\fB\-\-restart\-on\-signal=\fR[\fB!\fR]\fISIG\fR[\fB,\fISIG\fR...]]\
39 [\fB\-\-sentinel\fR]\ 41 [\fB\-\-sentinel\fR]\
40 [\fB\-\-signal\-reload=\fISIG\fR]\ 42 [\fB\-\-signal\-reload=\fISIG\fR]\
41 [\fB\-\-signal\-stop=\fISIG\fR]\ 43 [\fB\-\-signal\-stop=\fISIG\fR]\
42 [\fB\-\-timeout=\fISECONDS\fR]\ 44 [\fB\-\-timeout=\fISECONDS\fR]\
43 [\fB\-\-user=\fIUSER\fR]\ 45 [\fB\-\-user=\fIUSER\fR]\
44 [\fB\-\-usage\fR]\ 46 [\fB\-\-usage\fR]\
45 [\fB\-\-verbose\fR]\