Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Apr 2018 17:13:31 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r332943 - stable/11/usr.sbin/daemon
Message-ID:  <201804241713.w3OHDVjv032397@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Tue Apr 24 17:13:31 2018
New Revision: 332943
URL: https://svnweb.freebsd.org/changeset/base/332943

Log:
  MFC r332518, r332527
  
  r332518:
  Add an option to daemon(8) to specify a delay between restarts of a
  supervised program.  The existing -r option has a hard-coded delay of one
  second.  This change adds a -R option which takes a delay in seconds.  This
  can be used to prevent log spam and rapid restarts, similar to init(8)'s
  behavior of adding a delay between rapid restarts when it's supervising a
  program.
  
  r332527:
  Fix cut-and-pasted line to have the right option letter.

Modified:
  stable/11/usr.sbin/daemon/daemon.8
  stable/11/usr.sbin/daemon/daemon.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/daemon/daemon.8
==============================================================================
--- stable/11/usr.sbin/daemon/daemon.8	Tue Apr 24 17:00:08 2018	(r332942)
+++ stable/11/usr.sbin/daemon/daemon.8	Tue Apr 24 17:13:31 2018	(r332943)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 22, 2016
+.Dd April 15, 2018
 .Dt DAEMON 8
 .Os
 .Sh NAME
@@ -44,6 +44,7 @@
 .Op Fl s Ar syslog_priority
 .Op Fl T Ar syslog_tag
 .Op Fl l Ar syslog_facility
+.Op Fl R Ar restart_delay_seconds
 .Ar command arguments ...
 .Sh DESCRIPTION
 The
@@ -114,7 +115,11 @@ regardless of whether the
 .Fl u
 option is used or not.
 .It Fl r
-Supervise and restart the program if it has been terminated.
+Supervise and restart the program after a one-second delay if it has
+been terminated.
+.It Fl R restart_delay_seconds
+Supervise and restart the program after the specified delay
+if it has been terminated.
 .It Fl t Ar title
 Set the title for the daemon process.
 The default is the daemonized invocation.

Modified: stable/11/usr.sbin/daemon/daemon.c
==============================================================================
--- stable/11/usr.sbin/daemon/daemon.c	Tue Apr 24 17:00:08 2018	(r332942)
+++ stable/11/usr.sbin/daemon/daemon.c	Tue Apr 24 17:13:31 2018	(r332943)
@@ -99,7 +99,7 @@ main(int argc, char *argv[])
 	dosyslog = 0;
 	outfn = NULL;
 	title = NULL;
-	while ((ch = getopt(argc, argv, "cfSp:P:ru:o:s:l:t:l:m:T:")) != -1) {
+	while ((ch = getopt(argc, argv, "cfSp:P:ru:o:s:l:t:l:m:R:T:")) != -1) {
 		switch (ch) {
 		case 'c':
 			nochdir = 0;
@@ -130,6 +130,11 @@ main(int argc, char *argv[])
 		case 'r':
 			restart = 1;
 			break;
+		case 'R':
+			restart = strtol(optarg, &p, 0);
+			if (p == optarg || restart < 1)
+				errx(6, "invalid restart delay");
+			break;
 		case 's':
 			logpri = get_log_mapping(optarg, prioritynames);
 			if (logpri == -1)
@@ -359,7 +364,7 @@ restart:
 		goto exit;
 	}
 	if (restart && !terminate) {
-		daemon_sleep(1, 0);
+		daemon_sleep(restart, 0);
 		close(pfd[0]);
 		pfd[0] = -1;
 		goto restart;
@@ -558,7 +563,7 @@ usage(void)
 	    "usage: daemon [-cfrS] [-p child_pidfile] [-P supervisor_pidfile]\n"
 	    "              [-u user] [-o output_file] [-t title]\n"
 	    "              [-l syslog_facility] [-s syslog_priority]\n"
-	    "              [-T syslog_tag] [-m output_mask]\n"
+	    "              [-T syslog_tag] [-m output_mask] [-R restart_delay_secs]\n"
 	    "command arguments ...\n");
 	exit(1);
 }



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