aboutsummaryrefslogtreecommitdiff
path: root/src/genrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/genrc.c')
-rw-r--r--src/genrc.c50
1 files changed, 45 insertions, 5 deletions
diff --git a/src/genrc.c b/src/genrc.c
index 9052987..3dccbda 100644
--- a/src/genrc.c
+++ b/src/genrc.c
@@ -1,5 +1,5 @@
/* This file is part of genrc
-Copyryght (C) 2018 Sergey Poznyakoff
+Copyryght (C) 2018, 2019 Sergey Poznyakoff
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@@ -17,6 +17,7 @@ int genrc_signal_reload = SIGHUP;
GENRC_PID_CLOSURE *genrc_pid_closure;
char *genrc_create_pidfile;
int genrc_verbose;
+char *genrc_shell = SHELL;
enum {
@@ -42,6 +43,8 @@ struct option longopts[] = {
{ "no-reload", no_argument, 0, OPT_NO_RELOAD },
{ "signal-stop", required_argument, 0, OPT_SIGNAL_STOP },
{ "sentinel", no_argument, 0, 'S' },
+ { "shell", no_argument, 0, 's' },
+ { "exec", no_argument, 0, 'e' },
{ "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE },
{ "version", no_argument, 0, OPT_VERSION },
{ "verbose", no_argument, 0, 'v' },
@@ -51,7 +54,27 @@ struct option longopts[] = {
{ "restart-on-signal", required_argument, 0, OPT_RESTART_ON_SIGNAL },
{ NULL }
};
-char shortopts[] = "c:hF:g:P:p:St:u:v";
+char shortopts[2*sizeof(longopts)/sizeof(longopts[0])];
+
+static void
+shortopts_setup(void)
+{
+ int i;
+ char *p;
+
+ for (i = 0, p = shortopts; longopts[i].name; i++) {
+ if (longopts[i].val < 128) {
+ *p++ = longopts[i].val;
+ if (longopts[i].has_arg != no_argument) {
+ *p++ = ':';
+ if (longopts[i].has_arg == optional_argument)
+ *p++ = ':';
+ }
+ }
+ }
+ *p = 0;
+}
+
struct sigdefn {
char const *sig_name;
@@ -206,6 +229,9 @@ char const *help_msg[] = {
"",
" --sentinel PROGRAM runs in foreground; disconnect from the",
" controlling terminal, run it and act as a sentinel",
+ " -s, --shell=SHELL use SHELL instead of /bin/sh;",
+ " --shell=none to exec PROGRAM directly",
+ " -e, --exec same as --shell=none",
" --restart-on-exit=[!]CODE[,...]",
" restart the program if it exits with one of the",
" listed status codes",
@@ -240,7 +266,7 @@ char const *help_msg[] = {
" file <FILENAME>, written in language <LANG>",
"",
" GREP:<FILE>:s/<RX>/<REPL>/[<FLAGS>][;...]",
- " Grep for the first line in <FILE> that matches <RX>. If found, process",
+ " Grep for the first line in <FILE> that matches <RX>. If found,",
" replace the matched portion according to <REPL> and <FLAGS>. Use",
" the resulting string as PID. More sed expressions can be supplied",
" separated with semicolons.",
@@ -276,12 +302,13 @@ help(void)
char const *usage_msg[] = {
"genrc",
- "[-h]",
+ "[-hev]",
"[-F PIDFILE]",
"[-P SOURCE]",
"[-c COMMAND]",
"[-g GROUP[,GROUP...]]",
"[-p PROGRAM]",
+ "[-s SHELL]",
"[-t SECONDS]",
"[-u USER]",
"[--command=COMMAND]",
@@ -294,11 +321,13 @@ char const *usage_msg[] = {
"[--restart-on-exit=[!]CODE[,...]]",
"[--restart-on-signal=[!]SIG[,...]]",
"[--sentinel]",
+ "[--shell=SHELL]",
"[--signal-reload=SIG]",
"[--signal-stop=SIG]",
"[--timeout=SECONDS]",
"[--usage]",
"[--user=USER]",
+ "[--verbose]",
"{",
"start",
"|",
@@ -403,7 +432,8 @@ main(int argc, char **argv)
GENRC_COMMAND command;
setprogname(argv[0]);
-
+
+ shortopts_setup();
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL))
!= EOF) {
switch (c) {
@@ -419,6 +449,16 @@ main(int argc, char **argv)
case 'c':
setenv("GENRC_COMMAND", optarg, 1);
break;
+ case 'e':
+ genrc_shell = NULL;
+ break;
+ case 's':
+ if (strcmp(optarg, "no") == 0
+ || strcmp(optarg, "none") == 0)
+ genrc_shell = NULL;
+ else
+ genrc_shell = optarg;
+ break;
case 'p':
setenv("GENRC_PROGRAM", optarg, 1);
break;

Return to:

Send suggestions and report system problems to the System administrator.