aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-05-15 14:01:22 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-05-15 14:10:21 +0300
commit6f6211b261abdd0c342a108f8766ddc613da034a (patch)
tree49afaf34613cad36dfa401114e0acb03cde1ede6 /src
parentd0004608cb066135457dffafec10926d43f30eab (diff)
downloadgenrc-6f6211b261abdd0c342a108f8766ddc613da034a.tar.gz
genrc-6f6211b261abdd0c342a108f8766ddc613da034a.tar.bz2
Version 1.0
Diffstat (limited to 'src')
-rw-r--r--src/genrc.813
-rw-r--r--src/genrc.c19
-rw-r--r--src/genrc.h2
-rw-r--r--src/sentinel.c8
4 files changed, 31 insertions, 11 deletions
diff --git a/src/genrc.8 b/src/genrc.8
index 1255b45..920252e 100644
--- a/src/genrc.8
+++ b/src/genrc.8
@@ -26,6 +26,7 @@ genrc \- generic system initialization script helper
26 [\fB\-p\fR \fIPROGRAM\fR]\ 26 [\fB\-p\fR \fIPROGRAM\fR]\
27 [\fB\-t\fR \fISECONDS\fR]\ 27 [\fB\-t\fR \fISECONDS\fR]\
28 [\fB\-\-command=\fICOMMAND\fR]\ 28 [\fB\-\-command=\fICOMMAND\fR]\
29 [\fB\-\-create\-pidfile=\fIPIDFILE\fR]\
29 [\fB\-\-help\fR]\ 30 [\fB\-\-help\fR]\
30 [\fB\-\-no\-reload\fR]\ 31 [\fB\-\-no\-reload\fR]\
31 [\fB\-\-pid\-from=\fISOURCE\fR]\ 32 [\fB\-\-pid\-from=\fISOURCE\fR]\
@@ -89,10 +90,11 @@ to syslog facility \fBdaemon\fR. The standard output will be logged
89with the priority \fBinfo\fR and the error with the priority 90with the priority \fBinfo\fR and the error with the priority
90\fBerr\fR. 91\fBerr\fR.
91.PP 92.PP
92If the \fB\-\-pidfile=\fIFILE\fR option is given together with 93If the \fB\-\-create\-pidfile=\fIFILENAME\fR option is given together with
93\fB\-\-sentinel\fR, the PID of the subsidiary command will be stored 94\fB\-\-sentinel\fR, the PID of the subsidiary command will be stored
94in \fIFILE\fR. The file will be unlinked after the subsidiary command 95in \fIFILE\fR. The file will be unlinked after the subsidiary command
95terminates. 96terminates. Unless the \fB\-\-pid\-from\fR option is given,
97\fB\-\-pid\-from=FILE:\fIFILENAME\fR will be assumed.
96.SS status 98.SS status
97In \fBstatus\fR mode \fBgenrc\fR verifies if the \fICOMMAND\fR is 99In \fBstatus\fR mode \fBgenrc\fR verifies if the \fICOMMAND\fR is
98already running and outputs its status on the standard output. To this 100already running and outputs its status on the standard output. To this
@@ -149,6 +151,13 @@ exec /sbin/genrc \\
149\fB\-c\fR, \fB\-\-command=\fICOMMAND\fR 151\fB\-c\fR, \fB\-\-command=\fICOMMAND\fR
150Command line to run. 152Command line to run.
151.TP 153.TP
154\fB\-\-create\-pidfile=\fINAME\fR
155When used together with \fB\-\-sentinel\fR, the PID of the command
156being run will be stored in file \fINAME\fR. The
157\fB\-\-pid\-from=FILE:\fINAME\fR will be assumed, unless the
158\fB\-\-pid\-from\fR is given explicitly (or the \fBGENRC_PID_FROM\fR
159variable is set).
160.TP
152\fB\-F\fR, \fB\-\-pidfile=\fINAME\fR 161\fB\-F\fR, \fB\-\-pidfile=\fINAME\fR
153Name of the PID file (same as \fB\-\-pid\-from=FILE:\fINAME\fR) 162Name of the PID file (same as \fB\-\-pid\-from=FILE:\fINAME\fR)
154.TP 163.TP
diff --git a/src/genrc.c b/src/genrc.c
index ecc26fe..3f89d03 100644
--- a/src/genrc.c
+++ b/src/genrc.c
@@ -15,7 +15,7 @@ int genrc_no_reload;
15int genrc_signal_stop = SIGTERM; 15int genrc_signal_stop = SIGTERM;
16int genrc_signal_reload = SIGHUP; 16int genrc_signal_reload = SIGHUP;
17GENRC_PID_CLOSURE *genrc_pid_closure; 17GENRC_PID_CLOSURE *genrc_pid_closure;
18char *genrc_pidfile; 18char *genrc_create_pidfile;
19 19
20 20
21enum { 21enum {
@@ -23,7 +23,8 @@ enum {
23 OPT_VERSION, 23 OPT_VERSION,
24 OPT_SIGNAL_RELOAD, 24 OPT_SIGNAL_RELOAD,
25 OPT_NO_RELOAD, 25 OPT_NO_RELOAD,
26 OPT_SIGNAL_STOP 26 OPT_SIGNAL_STOP,
27 OPT_CREATE_PIDFILE
27}; 28};
28 29
29struct option longopts[] = { 30struct option longopts[] = {
@@ -38,6 +39,7 @@ struct option longopts[] = {
38 { "no-reload", no_argument, 0, OPT_NO_RELOAD }, 39 { "no-reload", no_argument, 0, OPT_NO_RELOAD },
39 { "signal-stop", required_argument, 0, OPT_SIGNAL_STOP }, 40 { "signal-stop", required_argument, 0, OPT_SIGNAL_STOP },
40 { "sentinel", no_argument, 0, 'S' }, 41 { "sentinel", no_argument, 0, 'S' },
42 { "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE },
41 { "version", no_argument, 0, OPT_VERSION }, 43 { "version", no_argument, 0, OPT_VERSION },
42 { NULL } 44 { NULL }
43}; 45};
@@ -147,7 +149,7 @@ sig_name_to_str(char const *s)
147 149
148char const *help_msg[] = { 150char const *help_msg[] = {
149 "Usage: genrc [OPTIONS] COMMAND", 151 "Usage: genrc [OPTIONS] COMMAND",
150 "generic rc program\n", 152 "generic system initialization script helper\n",
151 "COMMANDs are:\n", 153 "COMMANDs are:\n",
152 " start start the program", 154 " start start the program",
153 " stop stop the program", 155 " stop stop the program",
@@ -377,12 +379,14 @@ main(int argc, char **argv)
377 setenv("GENRC_PID_FROM", optarg, 1); 379 setenv("GENRC_PID_FROM", optarg, 1);
378 break; 380 break;
379 case 'F': 381 case 'F':
380 genrc_pidfile = optarg;
381 p = xmalloc(6 + strlen(optarg)); 382 p = xmalloc(6 + strlen(optarg));
382 strcat(strcpy(p, "FILE:"), optarg); 383 strcat(strcpy(p, "FILE:"), optarg);
383 setenv("GENRC_PID_FROM", p, 1); 384 setenv("GENRC_PID_FROM", p, 1);
384 free(p); 385 free(p);
385 break; 386 break;
387 case OPT_CREATE_PIDFILE:
388 setenv("GENRC_CREATE_PIDFILE", optarg, 1);
389 break;
386 case 't': 390 case 't':
387 setenv("GENRC_TIMEOUT", optarg, 1); 391 setenv("GENRC_TIMEOUT", optarg, 1);
388 break; 392 break;
@@ -454,8 +458,15 @@ main(int argc, char **argv)
454 wordsplit_free(&ws); 458 wordsplit_free(&ws);
455 } 459 }
456 460
461 genrc_create_pidfile = getenv("GENRC_CREATE_PIDFILE");
462
457 if ((p = getenv("GENRC_PID_FROM")) != NULL) { 463 if ((p = getenv("GENRC_PID_FROM")) != NULL) {
458 genrc_pid_closure = get_pid_closure(p); 464 genrc_pid_closure = get_pid_closure(p);
465 } else if (genrc_create_pidfile) {
466 p = xmalloc(6 + strlen(genrc_create_pidfile));
467 strcat(strcpy(p, "FILE:"), genrc_create_pidfile);
468 genrc_pid_closure = get_pid_closure(p);
469 free(p);
459 } else { 470 } else {
460 genrc_pid_closure = get_pid_closure("PROC"); 471 genrc_pid_closure = get_pid_closure("PROC");
461 } 472 }
diff --git a/src/genrc.h b/src/genrc.h
index 82e29d6..13b40d7 100644
--- a/src/genrc.h
+++ b/src/genrc.h
@@ -131,7 +131,7 @@ extern int genrc_no_reload;
131extern int genrc_signal_reload; 131extern int genrc_signal_reload;
132extern int genrc_signal_stop; 132extern int genrc_signal_stop;
133extern GENRC_PID_CLOSURE *genrc_pid_closure; 133extern GENRC_PID_CLOSURE *genrc_pid_closure;
134extern char *genrc_pidfile; 134extern char *genrc_create_pidfile;
135 135
136int sentinel(void); 136int sentinel(void);
137 137
diff --git a/src/sentinel.c b/src/sentinel.c
index 55395b3..1d44763 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -23,9 +23,9 @@ xpipe(int p[2])
23static void 23static void
24write_pid_file(pid_t pid) 24write_pid_file(pid_t pid)
25{ 25{
26 if (genrc_pidfile) { 26 if (genrc_create_pidfile) {
27 FILE *fp; 27 FILE *fp;
28 fp = fopen(genrc_pidfile, "w"); 28 fp = fopen(genrc_create_pidfile, "w");
29 fprintf(fp, "%lu\n", (unsigned long)pid); 29 fprintf(fp, "%lu\n", (unsigned long)pid);
30 fclose(fp); 30 fclose(fp);
31 } 31 }
@@ -83,8 +83,8 @@ wait_loop(pid_t child, int out, int err)
83 int rc, status; 83 int rc, status;
84 84
85 if (waitpid(child, &status, WNOHANG) == child) { 85 if (waitpid(child, &status, WNOHANG) == child) {
86 if (genrc_pidfile) 86 if (genrc_create_pidfile)
87 unlink(genrc_pidfile); 87 unlink(genrc_create_pidfile);
88 if (WIFEXITED(status)) { 88 if (WIFEXITED(status)) {
89 syslog(LOG_INFO, "%s exited with status %d", 89 syslog(LOG_INFO, "%s exited with status %d",
90 genrc_program, WEXITSTATUS(status)); 90 genrc_program, WEXITSTATUS(status));

Return to:

Send suggestions and report system problems to the System administrator.