aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhor Antonov <ihor@antonovs.family>2023-03-03 05:17:02 +0000
committerKyle Evans <kevans@FreeBSD.org>2023-03-03 05:17:02 +0000
commitf907027b49d93170ed2e92cf0d183cd643b1f70e (patch)
tree43e23684c3280be888843b0b0249d365721ad39a
parente781739084e9cb120ef4b6657074d2b7336ee405 (diff)
downloadsrc-f907027b49d93170ed2e92cf0d183cd643b1f70e.tar.gz
src-f907027b49d93170ed2e92cf0d183cd643b1f70e.zip
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
-rw-r--r--usr.sbin/daemon/daemon.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c
index 08ae5c74b8c2..3bbf092b500c 100644
--- a/usr.sbin/daemon/daemon.c
+++ b/usr.sbin/daemon/daemon.c
@@ -179,6 +179,23 @@ main(int argc, char *argv[])
sigemptyset(&mask_term);
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) {
switch (ch) {
case 'c':
@@ -197,6 +214,7 @@ main(int argc, char *argv[])
errx(5, "unrecognized syslog facility");
}
logparams.syslog_enabled = true;
+ supervision_enabled = true;
break;
case 'm':
stdmask = strtol(optarg, &p, 10);
@@ -206,15 +224,25 @@ main(int argc, char *argv[])
break;
case 'o':
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;
case 'p':
child_pidfile = optarg;
+ supervision_enabled = true;
break;
case 'P':
parent_pidfile = optarg;
+ supervision_enabled = true;
break;
case 'r':
restart_enabled = true;
+ supervision_enabled = true;
break;
case 'R':
restart_enabled = true;
@@ -230,9 +258,11 @@ main(int argc, char *argv[])
errx(4, "unrecognized syslog priority");
}
logparams.syslog_enabled = true;
+ supervision_enabled = true;
break;
case 'S':
logparams.syslog_enabled = true;
+ supervision_enabled = true;
break;
case 't':
title = optarg;
@@ -240,6 +270,7 @@ main(int argc, char *argv[])
case 'T':
logparams.syslog_tag = optarg;
logparams.syslog_enabled = true;
+ supervision_enabled = true;
break;
case 'u':
user = optarg;
@@ -286,29 +317,6 @@ main(int argc, char *argv[])
/* Write out parent pidfile if needed. */
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) {
struct sigaction act_term = { 0 };
struct sigaction act_chld = { 0 };