diff options
Diffstat (limited to 'src/genrc.c')
-rw-r--r-- | src/genrc.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/genrc.c b/src/genrc.c index ae3070d..9052987 100644 --- a/src/genrc.c +++ b/src/genrc.c | |||
@@ -27,3 +27,5 @@ enum { | |||
27 | OPT_SIGNAL_STOP, | 27 | OPT_SIGNAL_STOP, |
28 | OPT_CREATE_PIDFILE | 28 | OPT_CREATE_PIDFILE, |
29 | OPT_RESTART_ON_EXIT, | ||
30 | OPT_RESTART_ON_SIGNAL, | ||
29 | }; | 31 | }; |
@@ -47,2 +49,4 @@ struct option longopts[] = { | |||
47 | { "group", required_argument, 0, 'g' }, | 49 | { "group", required_argument, 0, 'g' }, |
50 | { "restart-on-exit", required_argument, 0, OPT_RESTART_ON_EXIT }, | ||
51 | { "restart-on-signal", required_argument, 0, OPT_RESTART_ON_SIGNAL }, | ||
48 | { NULL } | 52 | { NULL } |
@@ -129,5 +133,4 @@ is_numeric_str(char const *s) | |||
129 | int | 133 | int |
130 | sig_name_to_str(char const *s) | 134 | str_to_int(char const *s) |
131 | { | 135 | { |
132 | if (is_numeric_str(s)) { | ||
133 | char *end; | 136 | char *end; |
@@ -139,2 +142,9 @@ sig_name_to_str(char const *s) | |||
139 | return n; | 142 | return n; |
143 | } | ||
144 | |||
145 | int | ||
146 | str_to_sig(char const *s) | ||
147 | { | ||
148 | if (is_numeric_str(s)) { | ||
149 | return str_to_int(s); | ||
140 | } else { | 150 | } else { |
@@ -185,4 +195,2 @@ char const *help_msg[] = { | |||
185 | " terminate", | 195 | " terminate", |
186 | " --sentinel PROGRAM runs in foreground; disconnect from the", | ||
187 | " controlling terminal, run it and act as a sentinel", | ||
188 | " -P, --pid-from=SOURCE where to look for PIDs of the running programs", | 196 | " -P, --pid-from=SOURCE where to look for PIDs of the running programs", |
@@ -196,2 +204,13 @@ char const *help_msg[] = { | |||
196 | "", | 204 | "", |
205 | "Sentinel mode:", | ||
206 | "", | ||
207 | " --sentinel PROGRAM runs in foreground; disconnect from the", | ||
208 | " controlling terminal, run it and act as a sentinel", | ||
209 | " --restart-on-exit=[!]CODE[,...]", | ||
210 | " restart the program if it exits with one of the", | ||
211 | " listed status codes", | ||
212 | " --restart-on-signal=[!]SIG[,...]", | ||
213 | " restart the program if it terminates on one of the", | ||
214 | " listed signals", | ||
215 | "", | ||
197 | "Informational options:", | 216 | "Informational options:", |
@@ -274,2 +293,4 @@ char const *usage_msg[] = { | |||
274 | "[--program=PROGRAM]", | 293 | "[--program=PROGRAM]", |
294 | "[--restart-on-exit=[!]CODE[,...]]", | ||
295 | "[--restart-on-signal=[!]SIG[,...]]", | ||
275 | "[--sentinel]", | 296 | "[--sentinel]", |
@@ -424,2 +445,8 @@ main(int argc, char **argv) | |||
424 | break; | 445 | break; |
446 | case OPT_RESTART_ON_EXIT: | ||
447 | add_restart_condition(RESTART_ON_EXIT, optarg); | ||
448 | break; | ||
449 | case OPT_RESTART_ON_SIGNAL: | ||
450 | add_restart_condition(RESTART_ON_SIGNAL, optarg); | ||
451 | break; | ||
425 | case OPT_NO_RELOAD: | 452 | case OPT_NO_RELOAD: |
@@ -452,3 +479,3 @@ main(int argc, char **argv) | |||
452 | else if ((p = getenv("GENRC_SIGNAL_RELOAD")) != NULL) { | 479 | else if ((p = getenv("GENRC_SIGNAL_RELOAD")) != NULL) { |
453 | genrc_signal_reload = sig_name_to_str(p); | 480 | genrc_signal_reload = str_to_sig(p); |
454 | if (genrc_signal_reload == -1) | 481 | if (genrc_signal_reload == -1) |
@@ -460,3 +487,3 @@ main(int argc, char **argv) | |||
460 | if ((p = getenv("GENRC_SIGNAL_STOP")) != NULL) { | 487 | if ((p = getenv("GENRC_SIGNAL_STOP")) != NULL) { |
461 | genrc_signal_stop = sig_name_to_str(p); | 488 | genrc_signal_stop = str_to_sig(p); |
462 | if (genrc_signal_stop <= 0) | 489 | if (genrc_signal_stop <= 0) |