daemon: set supervise_enabled during argument processing
Now when supervsion mode has it's own variable there is really no reason to set it separately from the rest of the variables. Move initialization of supervise_enabled var to the argument processing switch loop, where it belongs. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
This commit is contained in:
parent
e781739084
commit
f907027b49
@ -179,6 +179,23 @@ main(int argc, char *argv[])
|
|||||||
sigemptyset(&mask_term);
|
sigemptyset(&mask_term);
|
||||||
sigemptyset(&mask_orig);
|
sigemptyset(&mask_orig);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Supervision mode is enabled if one of the following options are used:
|
||||||
|
* --child-pidfile -p
|
||||||
|
* --supervisor-pidfile -P
|
||||||
|
* --restart -r / --restart-delay -R
|
||||||
|
* --syslog -S
|
||||||
|
* --syslog-facility -l
|
||||||
|
* --syslog-priority -s
|
||||||
|
* --syslog-tag -T
|
||||||
|
*
|
||||||
|
* In supervision mode daemon executes the command in a forked process
|
||||||
|
* and observes the child by waiting for SIGCHILD. In supervision mode
|
||||||
|
* daemon must never exit before the child, this is necessary to prevent
|
||||||
|
* orphaning the child and leaving a stale pid file.
|
||||||
|
* To achieve this daemon catches SIGTERM and
|
||||||
|
* forwards it to the child, expecting to get SIGCHLD eventually.
|
||||||
|
*/
|
||||||
while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'c':
|
case 'c':
|
||||||
@ -197,6 +214,7 @@ main(int argc, char *argv[])
|
|||||||
errx(5, "unrecognized syslog facility");
|
errx(5, "unrecognized syslog facility");
|
||||||
}
|
}
|
||||||
logparams.syslog_enabled = true;
|
logparams.syslog_enabled = true;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
stdmask = strtol(optarg, &p, 10);
|
stdmask = strtol(optarg, &p, 10);
|
||||||
@ -206,15 +224,25 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
logparams.output_filename = optarg;
|
logparams.output_filename = optarg;
|
||||||
|
/*
|
||||||
|
* TODO: setting output filename doesn't have to turn
|
||||||
|
* the supervision mode on. For non-supervised mode
|
||||||
|
* daemon could open the specified file and set it's
|
||||||
|
* descriptor as both stderr and stout before execve()
|
||||||
|
*/
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
child_pidfile = optarg;
|
child_pidfile = optarg;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
parent_pidfile = optarg;
|
parent_pidfile = optarg;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
restart_enabled = true;
|
restart_enabled = true;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
restart_enabled = true;
|
restart_enabled = true;
|
||||||
@ -230,9 +258,11 @@ main(int argc, char *argv[])
|
|||||||
errx(4, "unrecognized syslog priority");
|
errx(4, "unrecognized syslog priority");
|
||||||
}
|
}
|
||||||
logparams.syslog_enabled = true;
|
logparams.syslog_enabled = true;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
logparams.syslog_enabled = true;
|
logparams.syslog_enabled = true;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
title = optarg;
|
title = optarg;
|
||||||
@ -240,6 +270,7 @@ main(int argc, char *argv[])
|
|||||||
case 'T':
|
case 'T':
|
||||||
logparams.syslog_tag = optarg;
|
logparams.syslog_tag = optarg;
|
||||||
logparams.syslog_enabled = true;
|
logparams.syslog_enabled = true;
|
||||||
|
supervision_enabled = true;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
user = optarg;
|
user = optarg;
|
||||||
@ -286,29 +317,6 @@ main(int argc, char *argv[])
|
|||||||
/* Write out parent pidfile if needed. */
|
/* Write out parent pidfile if needed. */
|
||||||
pidfile_write(parent_pidfh);
|
pidfile_write(parent_pidfh);
|
||||||
|
|
||||||
/*
|
|
||||||
* Supervision mode is enabled if one of the following options are used:
|
|
||||||
* --child-pidfile -p
|
|
||||||
* --supervisor-pidfile -P
|
|
||||||
* --restart -r / --restart-delay -R
|
|
||||||
* --syslog -S
|
|
||||||
* --syslog-facility -l
|
|
||||||
* --syslog-priority -s
|
|
||||||
* --syslog-tag -T
|
|
||||||
*
|
|
||||||
* In supervision mode daemon executes the command in a forked process
|
|
||||||
* and observes the child by waiting for SIGCHILD. In supervision mode
|
|
||||||
* daemon must never exit before the child, this is necessary to prevent
|
|
||||||
* orphaning the child and leaving a stale pid file.
|
|
||||||
* To achieve this daemon catches SIGTERM and
|
|
||||||
* forwards it to the child, expecting to get SIGCHLD eventually.
|
|
||||||
*/
|
|
||||||
supervision_enabled = child_pidfile != NULL ||
|
|
||||||
parent_pidfile != NULL ||
|
|
||||||
restart_enabled == true ||
|
|
||||||
logparams.output_fd != -1 ||
|
|
||||||
logparams.syslog_enabled == true;
|
|
||||||
|
|
||||||
if (supervision_enabled) {
|
if (supervision_enabled) {
|
||||||
struct sigaction act_term = { 0 };
|
struct sigaction act_term = { 0 };
|
||||||
struct sigaction act_chld = { 0 };
|
struct sigaction act_chld = { 0 };
|
||||||
|
Loading…
Reference in New Issue
Block a user