aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/daemon
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2019-06-04 16:07:01 +0000
committerConrad Meyer <cem@FreeBSD.org>2019-06-04 16:07:01 +0000
commit09a3675d961ffde1d6cebbb40412a4ae77bd3d3c (patch)
tree8175b1111c2c0ed016dabd206b933686c955cb3a /usr.sbin/daemon
parentb734222edd7402931f2611d9613963ef093d834a (diff)
downloadsrc-09a3675d961ffde1d6cebbb40412a4ae77bd3d3c.tar.gz
src-09a3675d961ffde1d6cebbb40412a4ae77bd3d3c.zip
daemon(8): Don't block SIGTERM during restart delay
I believe this was introduced in the original '-r' commit, r231911 (2012). At the time, the scope was limited to a 1 second sleep. r332518 (2018) added '-R', which increased the potential duration of the affected interval (from 1 to N seconds) by permitting arbitrary restart intervals. Instead, handle SIGTERM normally during restart-sleep, when the monitored process is not running, and shut down promptly. (I noticed this behavior when debugging a child process that exited quickly under the 'daemon -r -R 30' environment. 'kill <daemonpid>' had no immediate effect and the monitor process slept until the next restart attempt. This was annoying.) Reviewed by: allanjude, imp, markj Differential Revision: https://reviews.freebsd.org/D20509
Notes
Notes: svn path=/head/; revision=348629
Diffstat (limited to 'usr.sbin/daemon')
-rw-r--r--usr.sbin/daemon/daemon.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c
index ad3d9fd34f14..7a245421e4df 100644
--- a/usr.sbin/daemon/daemon.c
+++ b/usr.sbin/daemon/daemon.c
@@ -359,12 +359,13 @@ restart:
}
}
}
+ if (restart && !terminate)
+ daemon_sleep(restart, 0);
if (sigprocmask(SIG_BLOCK, &mask_term, NULL)) {
warn("sigprocmask");
goto exit;
}
if (restart && !terminate) {
- daemon_sleep(restart, 0);
close(pfd[0]);
pfd[0] = -1;
goto restart;
@@ -384,7 +385,8 @@ static void
daemon_sleep(time_t secs, long nsecs)
{
struct timespec ts = { secs, nsecs };
- while (nanosleep(&ts, &ts) == -1) {
+
+ while (!terminate && nanosleep(&ts, &ts) == -1) {
if (errno != EINTR)
err(1, "nanosleep");
}