Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jun 2019 16:07:01 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r348629 - head/usr.sbin/daemon
Message-ID:  <201906041607.x54G71gb054740@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Tue Jun  4 16:07:01 2019
New Revision: 348629
URL: https://svnweb.freebsd.org/changeset/base/348629

Log:
  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

Modified:
  head/usr.sbin/daemon/daemon.c

Modified: head/usr.sbin/daemon/daemon.c
==============================================================================
--- head/usr.sbin/daemon/daemon.c	Tue Jun  4 15:44:31 2019	(r348628)
+++ head/usr.sbin/daemon/daemon.c	Tue Jun  4 16:07:01 2019	(r348629)
@@ -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");
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906041607.x54G71gb054740>