Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Aug 2016 18:12:49 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r304570 - head/usr.sbin/cron/cron
Message-ID:  <201608211812.u7LICnEI013156@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Sun Aug 21 18:12:49 2016
New Revision: 304570
URL: https://svnweb.freebsd.org/changeset/base/304570

Log:
  Add the "-n" flag to cron(8), to prevent it from daemonizing.
  This makes it possible to use it with external supervisors.
  The "-n" flag name is compatible with Linux, NetBSD, and OpenBSD.
  
  Reviewed by:	jilles, pfg, wblock
  MFC after:	1 month
  Differential Revision:	https://reviews.freebsd.org/D7581

Modified:
  head/usr.sbin/cron/cron/cron.8
  head/usr.sbin/cron/cron/cron.c

Modified: head/usr.sbin/cron/cron/cron.8
==============================================================================
--- head/usr.sbin/cron/cron/cron.8	Sun Aug 21 17:57:32 2016	(r304569)
+++ head/usr.sbin/cron/cron/cron.8	Sun Aug 21 18:12:49 2016	(r304570)
@@ -17,7 +17,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 29, 2008
+.Dd August 21, 2016
 .Dt CRON 8
 .Os
 .Sh NAME
@@ -28,6 +28,7 @@
 .Op Fl j Ar jitter
 .Op Fl J Ar rootjitter
 .Op Fl m Ar mailto
+.Op Fl n
 .Op Fl s
 .Op Fl o
 .Op Fl x Ar debugflag Ns Op , Ns Ar ...
@@ -132,6 +133,8 @@ set to a null string, usually specified 
 .Li ''
 or
 .Li \*q\*q .
+.It Fl n
+Don't daemonize, run in foreground instead.
 .It Fl s
 Enable special handling of situations when the GMT offset of the local
 timezone changes, such as the switches between the standard time and

Modified: head/usr.sbin/cron/cron/cron.c
==============================================================================
--- head/usr.sbin/cron/cron/cron.c	Sun Aug 21 17:57:32 2016	(r304569)
+++ head/usr.sbin/cron/cron/cron.c	Sun Aug 21 18:12:49 2016	(r304570)
@@ -49,6 +49,7 @@ static int	run_at_secres(cron_db *);
 
 static time_t	last_time = 0;
 static int	dst_enabled = 0;
+static int	dont_daemonize = 0;
 struct pidfh *pfh;
 
 static void
@@ -58,7 +59,7 @@ usage() {
 #endif
 
 	fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] "
-			"[-m mailto] [-s] [-o] [-x debugflag[,...]]\n");
+			"[-m mailto] [-n ] [-s] [-o] [-x debugflag[,...]]\n");
 #if DEBUGGING
 	fprintf(stderr, "\ndebugflags: ");
 
@@ -136,7 +137,7 @@ main(argc, argv)
 	if (0) {
 # endif
 		(void) fprintf(stderr, "[%d] cron started\n", getpid());
-	} else {
+	} else if (dont_daemonize == 0) {
 		if (daemon(1, 0) == -1) {
 			pidfile_remove(pfh);
 			log_it("CRON",getpid(),"DEATH","can't become daemon");
@@ -512,7 +513,7 @@ parse_args(argc, argv)
 	int	argch;
 	char	*endp;
 
-	while ((argch = getopt(argc, argv, "j:J:m:osx:")) != -1) {
+	while ((argch = getopt(argc, argv, "j:J:m:nosx:")) != -1) {
 		switch (argch) {
 		case 'j':
 			Jitter = strtoul(optarg, &endp, 10);
@@ -529,6 +530,9 @@ parse_args(argc, argv)
 		case 'm':
 			defmailto = optarg;
 			break;
+		case 'n':
+			dont_daemonize = 1;
+			break;
 		case 'o':
 			dst_enabled = 0;
 			break;



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