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
@@ -28,2 +28,3 @@ genrc \- generic system initialization script helper
[\fB\-\-command=\fICOMMAND\fR]\
+ [\fB\-\-create\-pidfile=\fIPIDFILE\fR]\
[\fB\-\-help\fR]\
@@ -91,6 +92,7 @@ with the priority \fBinfo\fR and the error with the priority
.PP
-If the \fB\-\-pidfile=\fIFILE\fR option is given together with
+If the \fB\-\-create\-pidfile=\fIFILENAME\fR option is given together with
\fB\-\-sentinel\fR, the PID of the subsidiary command will be stored
in \fIFILE\fR. The file will be unlinked after the subsidiary command
-terminates.
+terminates. Unless the \fB\-\-pid\-from\fR option is given,
+\fB\-\-pid\-from=FILE:\fIFILENAME\fR will be assumed.
.SS status
@@ -151,2 +153,9 @@ Command line to run.
.TP
+\fB\-\-create\-pidfile=\fINAME\fR
+When used together with \fB\-\-sentinel\fR, the PID of the command
+being run will be stored in file \fINAME\fR. The
+\fB\-\-pid\-from=FILE:\fINAME\fR will be assumed, unless the
+\fB\-\-pid\-from\fR is given explicitly (or the \fBGENRC_PID_FROM\fR
+variable is set).
+.TP
\fB\-F\fR, \fB\-\-pidfile=\fINAME\fR
diff --git a/src/genrc.c b/src/genrc.c
index ecc26fe..3f89d03 100644
--- a/src/genrc.c
+++ b/src/genrc.c
@@ -17,3 +17,3 @@ int genrc_signal_reload = SIGHUP;
GENRC_PID_CLOSURE *genrc_pid_closure;
-char *genrc_pidfile;
+char *genrc_create_pidfile;
@@ -25,3 +25,4 @@ enum {
OPT_NO_RELOAD,
- OPT_SIGNAL_STOP
+ OPT_SIGNAL_STOP,
+ OPT_CREATE_PIDFILE
};
@@ -40,2 +41,3 @@ struct option longopts[] = {
{ "sentinel", no_argument, 0, 'S' },
+ { "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE },
{ "version", no_argument, 0, OPT_VERSION },
@@ -149,3 +151,3 @@ char const *help_msg[] = {
"Usage: genrc [OPTIONS] COMMAND",
- "generic rc program\n",
+ "generic system initialization script helper\n",
"COMMANDs are:\n",
@@ -379,3 +381,2 @@ main(int argc, char **argv)
case 'F':
- genrc_pidfile = optarg;
p = xmalloc(6 + strlen(optarg));
@@ -385,2 +386,5 @@ main(int argc, char **argv)
break;
+ case OPT_CREATE_PIDFILE:
+ setenv("GENRC_CREATE_PIDFILE", optarg, 1);
+ break;
case 't':
@@ -456,4 +460,11 @@ main(int argc, char **argv)
+ genrc_create_pidfile = getenv("GENRC_CREATE_PIDFILE");
+
if ((p = getenv("GENRC_PID_FROM")) != NULL) {
genrc_pid_closure = get_pid_closure(p);
+ } else if (genrc_create_pidfile) {
+ p = xmalloc(6 + strlen(genrc_create_pidfile));
+ strcat(strcpy(p, "FILE:"), genrc_create_pidfile);
+ genrc_pid_closure = get_pid_closure(p);
+ free(p);
} else {
diff --git a/src/genrc.h b/src/genrc.h
index 82e29d6..13b40d7 100644
--- a/src/genrc.h
+++ b/src/genrc.h
@@ -133,3 +133,3 @@ extern int genrc_signal_stop;
extern GENRC_PID_CLOSURE *genrc_pid_closure;
-extern char *genrc_pidfile;
+extern char *genrc_create_pidfile;
diff --git a/src/sentinel.c b/src/sentinel.c
index 55395b3..1d44763 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -25,5 +25,5 @@ write_pid_file(pid_t pid)
{
- if (genrc_pidfile) {
+ if (genrc_create_pidfile) {
FILE *fp;
- fp = fopen(genrc_pidfile, "w");
+ fp = fopen(genrc_create_pidfile, "w");
fprintf(fp, "%lu\n", (unsigned long)pid);
@@ -85,4 +85,4 @@ wait_loop(pid_t child, int out, int err)
if (waitpid(child, &status, WNOHANG) == child) {
- if (genrc_pidfile)
- unlink(genrc_pidfile);
+ if (genrc_create_pidfile)
+ unlink(genrc_create_pidfile);
if (WIFEXITED(status)) {

Return to:

Send suggestions and report system problems to the System administrator.