diff options
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/com_start.c | 1 | ||||
-rw-r--r-- | src/genrc.8 | 25 | ||||
-rw-r--r-- | src/genrc.c | 10 | ||||
-rw-r--r-- | src/genrc.h | 2 | ||||
-rw-r--r-- | src/runas.c | 191 | ||||
-rw-r--r-- | src/sentinel.c | 2 |
7 files changed, 232 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f78a979..b565303 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -33,13 +33,14 @@ genrc_SOURCES = \ | |||
33 | com_restart.c\ | 33 | com_restart.c\ |
34 | com_reload.c\ | 34 | com_reload.c\ |
35 | transform.c\ | 35 | transform.c\ |
36 | match_exact.c\ | 36 | match_exact.c\ |
37 | match_glob.c\ | 37 | match_glob.c\ |
38 | match_regex.c\ | 38 | match_regex.c\ |
39 | sentinel.c | 39 | sentinel.c\ |
40 | runas.c | ||
40 | 41 | ||
41 | AM_CPPFLAGS = @GRECS_INCLUDES@ | 42 | AM_CPPFLAGS = @GRECS_INCLUDES@ |
42 | LDADD = @GRECS_LDADD@ | 43 | LDADD = @GRECS_LDADD@ |
43 | 44 | ||
44 | if COND_PCRE | 45 | if COND_PCRE |
45 | genrc_SOURCES += match_pcre.c | 46 | genrc_SOURCES += match_pcre.c |
diff --git a/src/com_start.c b/src/com_start.c index 65c1775..5744e39 100644 --- a/src/com_start.c +++ b/src/com_start.c | |||
@@ -109,12 +109,13 @@ com_start(void) | |||
109 | system_error(errno, "fork"); | 109 | system_error(errno, "fork"); |
110 | return 1; | 110 | return 1; |
111 | } | 111 | } |
112 | if (pid == 0) { | 112 | if (pid == 0) { |
113 | char *argv[] = { SHELL, "-c", NULL, NULL }; | 113 | char *argv[] = { SHELL, "-c", NULL, NULL }; |
114 | argv[2] = genrc_command; | 114 | argv[2] = genrc_command; |
115 | runas(); | ||
115 | execvp(SHELL, argv); | 116 | execvp(SHELL, argv); |
116 | system_error(errno, "failed to exec %s", genrc_program); | 117 | system_error(errno, "failed to exec %s", genrc_program); |
117 | exit(127); | 118 | exit(127); |
118 | } | 119 | } |
119 | 120 | ||
120 | if (timedwaitpid(pid, &status)) { | 121 | if (timedwaitpid(pid, &status)) { |
diff --git a/src/genrc.8 b/src/genrc.8 index f900639..00522ee 100644 --- a/src/genrc.8 +++ b/src/genrc.8 | |||
@@ -15,30 +15,35 @@ | |||
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 17, 2018" "GENRC" "Genrc User Manual" |
17 | .SH NAME | 17 | .SH NAME |
18 | genrc \- generic system initialization script helper | 18 | genrc \- generic system initialization script helper |
19 | .SH SYNOPSIS | 19 | .SH SYNOPSIS |
20 | .nh | 20 | .nh |
21 | .na | ||
21 | \fBgenrc\fR\ | 22 | \fBgenrc\fR\ |
22 | [\fB\-hv\fR]\ | 23 | [\fB\-hv\fR]\ |
23 | [\fB\-F\fR \fIPIDFILE\fR]\ | 24 | [\fB\-F\fR \fIPIDFILE\fR]\ |
24 | [\fB\-P\fR \fISOURCE\fR]\ | 25 | [\fB\-P\fR \fISOURCE\fR]\ |
25 | [\fB\-c\fR \fICOMMAND\fR]\ | 26 | [\fB\-c\fR \fICOMMAND\fR]\ |
27 | [\fB\-g\fR \fIGROUP\fR[,\fIGROUP\fR...]]\ | ||
26 | [\fB\-p\fR \fIPROGRAM\fR]\ | 28 | [\fB\-p\fR \fIPROGRAM\fR]\ |
27 | [\fB\-t\fR \fISECONDS\fR]\ | 29 | [\fB\-t\fR \fISECONDS\fR]\ |
30 | [\fB\-u\fR \fIUSER\fR]\ | ||
28 | [\fB\-\-command=\fICOMMAND\fR]\ | 31 | [\fB\-\-command=\fICOMMAND\fR]\ |
29 | [\fB\-\-create\-pidfile=\fIPIDFILE\fR]\ | 32 | [\fB\-\-create\-pidfile=\fIPIDFILE\fR]\ |
33 | [\fB\-\-group=\fIGROUP\fR[,\fIGROUP\fR...]]\ | ||
30 | [\fB\-\-help\fR]\ | 34 | [\fB\-\-help\fR]\ |
31 | [\fB\-\-no\-reload\fR]\ | 35 | [\fB\-\-no\-reload\fR]\ |
32 | [\fB\-\-pid\-from=\fISOURCE\fR]\ | 36 | [\fB\-\-pid\-from=\fISOURCE\fR]\ |
33 | [\fB\-\-pidfile=\fIPIDFILE\fR]\ | 37 | [\fB\-\-pidfile=\fIPIDFILE\fR]\ |
34 | [\fB\-\-program=\fIPROGRAM\fR]\ | 38 | [\fB\-\-program=\fIPROGRAM\fR]\ |
35 | [\fB\-\-sentinel\fR]\ | 39 | [\fB\-\-sentinel\fR]\ |
36 | [\fB\-\-signal\-reload=\fISIG\fR]\ | 40 | [\fB\-\-signal\-reload=\fISIG\fR]\ |
37 | [\fB\-\-signal\-stop=\fISIG\fR]\ | 41 | [\fB\-\-signal\-stop=\fISIG\fR]\ |
38 | [\fB\-\-timeout=\fISECONDS\fR]\ | 42 | [\fB\-\-timeout=\fISECONDS\fR]\ |
43 | [\fB\-\-user=\fIUSER\fR]\ | ||
39 | [\fB\-\-usage\fR]\ | 44 | [\fB\-\-usage\fR]\ |
40 | [\fB\-\-verbose\fR]\ | 45 | [\fB\-\-verbose\fR]\ |
41 | {\ | 46 | {\ |
42 | \fBstart\fR\ | 47 | \fBstart\fR\ |
43 | |\ | 48 | |\ |
44 | \fBstop\fR\ | 49 | \fBstop\fR\ |
@@ -162,12 +167,21 @@ variable is set). | |||
162 | \fB\-F\fR, \fB\-\-pidfile=\fINAME\fR | 167 | \fB\-F\fR, \fB\-\-pidfile=\fINAME\fR |
163 | Name of the PID file (same as \fB\-\-pid\-from=FILE:\fINAME\fR) | 168 | Name of the PID file (same as \fB\-\-pid\-from=FILE:\fINAME\fR) |
164 | .TP | 169 | .TP |
165 | \fB\-h\fR, \fB\-\-help\fR | 170 | \fB\-h\fR, \fB\-\-help\fR |
166 | Display a short help list. | 171 | Display a short help list. |
167 | .TP | 172 | .TP |
173 | \fB\-g\fR, \fB\-\-group=\fIGROUP\fR[,\fIGROUP\fR...] | ||
174 | Run program with this \fIGROUP\fR privileges. If the argument is a | ||
175 | list of groups, the first group becomes the principal, and the | ||
176 | rest of them supplementary groups. Each \fIGROUP\fR is either a group | ||
177 | name or a numeric group number prefixed with a plus sign. Whatever | ||
178 | notation is used, it must exist in the system group database. | ||
179 | |||
180 | See also the \fB\-\-user\fR option. | ||
181 | .TP | ||
168 | \fB\-\-no\-reload\fR | 182 | \fB\-\-no\-reload\fR |
169 | Makes \fBreload\fR equivalent to \fBrestart\fR. | 183 | Makes \fBreload\fR equivalent to \fBrestart\fR. |
170 | .TP | 184 | .TP |
171 | \fB\-p\fR, \fB\-\-program=\fIPROGRAM\fR | 185 | \fB\-p\fR, \fB\-\-program=\fIPROGRAM\fR |
172 | Name of the program to run. | 186 | Name of the program to run. |
173 | .TP | 187 | .TP |
@@ -189,12 +203,21 @@ Signal to send in order to terminate the program (default: | |||
189 | \fB\-t\fR, \fB\-\-timeout=\fISECONDS\fR | 203 | \fB\-t\fR, \fB\-\-timeout=\fISECONDS\fR |
190 | Time to wait for the program to start up or terminate. | 204 | Time to wait for the program to start up or terminate. |
191 | .TP | 205 | .TP |
192 | \fB\-\-usage\fR | 206 | \fB\-\-usage\fR |
193 | Display a short usage summary. | 207 | Display a short usage summary. |
194 | .TP | 208 | .TP |
209 | \fB\-u\fR, \fB\-\-user=\fIUSER\fR | ||
210 | Run with this user privileges. The argument is either a login | ||
211 | name or a numeric UID prefixed with the plus sign. Whatever form is | ||
212 | used, it must correspond to a valid user from the system user | ||
213 | database. | ||
214 | |||
215 | Unless \fB\-\-group\fR option is also given, the primary and | ||
216 | supplementary groups of \fIUSER\fR will be used. | ||
217 | .TP | ||
195 | \fB\-\-version\fR | 218 | \fB\-\-version\fR |
196 | Display program version and exit. | 219 | Display program version and exit. |
197 | .TP | 220 | .TP |
198 | \fB\-v\fR, \fB\-\-verbose\fR | 221 | \fB\-v\fR, \fB\-\-verbose\fR |
199 | Print verbose messages (e.g. "Starting \fIPROGNAME\fR"). | 222 | Print verbose messages (e.g. "Starting \fIPROGNAME\fR"). |
200 | .SH PID SOURCES | 223 | .SH PID SOURCES |
@@ -279,12 +302,14 @@ Influential environment variables and corresponding options: | |||
279 | \fBGENRC_COMMAND=\fICOMMAND\fR \fB\-\-command=\fICOMMAND\fR | 302 | \fBGENRC_COMMAND=\fICOMMAND\fR \fB\-\-command=\fICOMMAND\fR |
280 | \fBGENRC_PROGRAM=\fINAME\fR \fB\-\-program=\fINAME\fR | 303 | \fBGENRC_PROGRAM=\fINAME\fR \fB\-\-program=\fINAME\fR |
281 | \fBGENRC_PID_FROM=\fISOURCE\fR \fB\-\-pid\-from=\fISOURCE\fR | 304 | \fBGENRC_PID_FROM=\fISOURCE\fR \fB\-\-pid\-from=\fISOURCE\fR |
282 | \fBGENRC_TIMEOUT=\fISECONDS\fR \fB\-\-timeout=\fISECONDS\fR | 305 | \fBGENRC_TIMEOUT=\fISECONDS\fR \fB\-\-timeout=\fISECONDS\fR |
283 | \fBGENRC_SENTINEL=1\fR \fB\-\-sentinel\fR | 306 | \fBGENRC_SENTINEL=1\fR \fB\-\-sentinel\fR |
284 | \fBGENRC_CREATE_PIDFILE=\fINAME\fR \fB\-\-create\-pidfile=\fINAME\fR | 307 | \fBGENRC_CREATE_PIDFILE=\fINAME\fR \fB\-\-create\-pidfile=\fINAME\fR |
308 | \fBGENRC_USER=\fINAME\fR \fB\-\-user=\fINAME\fR | ||
309 | \fBGENRC_GROUP=\fIGROUPS\fR \fB\-\-group=\fIGROUPS\fR | ||
285 | .fi | 310 | .fi |
286 | .SH AUTHORS | 311 | .SH AUTHORS |
287 | Sergey Poznyakoff | 312 | Sergey Poznyakoff |
288 | .SH "BUG REPORTS" | 313 | .SH "BUG REPORTS" |
289 | Report bugs to <gray@gnu.org>. | 314 | Report bugs to <gray@gnu.org>. |
290 | .SH COPYRIGHT | 315 | .SH COPYRIGHT |
diff --git a/src/genrc.c b/src/genrc.c index 92b0fac..d4904b6 100644 --- a/src/genrc.c +++ b/src/genrc.c | |||
@@ -40,15 +40,17 @@ struct option longopts[] = { | |||
40 | { "no-reload", no_argument, 0, OPT_NO_RELOAD }, | 40 | { "no-reload", no_argument, 0, OPT_NO_RELOAD }, |
41 | { "signal-stop", required_argument, 0, OPT_SIGNAL_STOP }, | 41 | { "signal-stop", required_argument, 0, OPT_SIGNAL_STOP }, |
42 | { "sentinel", no_argument, 0, 'S' }, | 42 | { "sentinel", no_argument, 0, 'S' }, |
43 | { "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE }, | 43 | { "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE }, |
44 | { "version", no_argument, 0, OPT_VERSION }, | 44 | { "version", no_argument, 0, OPT_VERSION }, |
45 | { "verbose", no_argument, 0, 'v' }, | 45 | { "verbose", no_argument, 0, 'v' }, |
46 | { "user", required_argument, 0, 'u' }, | ||
47 | { "group", required_argument, 0, 'g' }, | ||
46 | { NULL } | 48 | { NULL } |
47 | }; | 49 | }; |
48 | char shortopts[] = "c:hF:P:p:St:v"; | 50 | char shortopts[] = "c:hF:g:P:p:St:u:v"; |
49 | 51 | ||
50 | struct sigdefn { | 52 | struct sigdefn { |
51 | char const *sig_name; | 53 | char const *sig_name; |
52 | int sig_no; | 54 | int sig_no; |
53 | }; | 55 | }; |
54 | 56 | ||
@@ -383,12 +385,15 @@ main(int argc, char **argv) | |||
383 | case 'F': | 385 | case 'F': |
384 | p = xmalloc(6 + strlen(optarg)); | 386 | p = xmalloc(6 + strlen(optarg)); |
385 | strcat(strcpy(p, "FILE:"), optarg); | 387 | strcat(strcpy(p, "FILE:"), optarg); |
386 | setenv("GENRC_PID_FROM", p, 1); | 388 | setenv("GENRC_PID_FROM", p, 1); |
387 | free(p); | 389 | free(p); |
388 | break; | 390 | break; |
391 | case 'g': | ||
392 | setenv("GENRC_GROUP", optarg, 1); | ||
393 | break; | ||
389 | case OPT_CREATE_PIDFILE: | 394 | case OPT_CREATE_PIDFILE: |
390 | setenv("GENRC_CREATE_PIDFILE", optarg, 1); | 395 | setenv("GENRC_CREATE_PIDFILE", optarg, 1); |
391 | break; | 396 | break; |
392 | case 't': | 397 | case 't': |
393 | setenv("GENRC_TIMEOUT", optarg, 1); | 398 | setenv("GENRC_TIMEOUT", optarg, 1); |
394 | break; | 399 | break; |
@@ -401,12 +406,15 @@ main(int argc, char **argv) | |||
401 | case OPT_SIGNAL_RELOAD: | 406 | case OPT_SIGNAL_RELOAD: |
402 | setenv("GENRC_SIGNAL_RELOAD", optarg, 1); | 407 | setenv("GENRC_SIGNAL_RELOAD", optarg, 1); |
403 | break; | 408 | break; |
404 | case OPT_SIGNAL_STOP: | 409 | case OPT_SIGNAL_STOP: |
405 | setenv("GENRC_SIGNAL_STOP", optarg, 1); | 410 | setenv("GENRC_SIGNAL_STOP", optarg, 1); |
406 | break; | 411 | break; |
412 | case 'u': | ||
413 | setenv("GENRC_USER", optarg, 1); | ||
414 | break; | ||
407 | case 'v': | 415 | case 'v': |
408 | genrc_verbose++; | 416 | genrc_verbose++; |
409 | break; | 417 | break; |
410 | default: | 418 |