1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
From: Christian Kastner <ckk@kvr.at>
Date: Sun, 10 Jan 2016 20:38:26 +0100
Subject: Enable running daemon in foreground
Enable running the daemon in the foreground by specifying -f as an option.
Contributed by Steve Greenland <stevegr@debian.org>.
Bug-Debian: https://bugs.debian.org/108492
Forwarded: no
Last-Update: 2016-01-10
---
cron.8 | 4 ++++
cron.c | 10 +++++++---
cron.h | 1 +
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/cron.8 b/cron.8
index 2ba9b34..23a50c0 100644
--- a/cron.8
+++ b/cron.8
@@ -23,6 +23,7 @@
cron \- daemon to execute scheduled commands (Vixie Cron)
.SH SYNOPSIS
cron
+.RB [ \-f ]
.RB [ \-l ]
.SH DESCRIPTION
.I cron
@@ -30,6 +31,9 @@ is started automatically from /etc/init.d on entering multi-user
runlevels.
.SH OPTIONS
.TP 8
+.B \-f
+Stay in foreground mode, don't daemonize.
+.TP
.B \-l
Enable LSB compliant names for /etc/cron.d files. This setting, however, does
not affect the parsing of files under /etc/cron.hourly, /etc/cron.daily,
diff --git a/cron.c b/cron.c
index db0e073..53a6dae 100644
--- a/cron.c
+++ b/cron.c
@@ -119,7 +119,7 @@ main(argc, argv)
if (0) {
# endif
(void) fprintf(stderr, "[%d] cron started\n", getpid());
- } else {
+ } else if (!stay_foreground) {
switch (fork()) {
case -1:
log_it("CRON",getpid(),"DEATH","can't fork");
@@ -447,9 +447,9 @@ sighup_handler(int x) {
#if DEBUGGING
-const char *getoptarg = "lx:";
+const char *getoptarg = "flx:";
#else
-const char *getoptarg = "l";
+const char *getoptarg = "fl";
#endif
static void
@@ -459,12 +459,16 @@ parse_args(argc, argv)
{
int argch;
+ stay_foreground = 0;
lsbsysinit_mode = 0;
while (EOF != (argch = getopt(argc, argv, getoptarg))) {
switch (argch) {
default:
usage();
+ case 'f':
+ stay_foreground = 1;
+ break;
case 'l':
lsbsysinit_mode = 1;
break;
diff --git a/cron.h b/cron.h
index 2a12bd2..30b36e9 100644
--- a/cron.h
+++ b/cron.h
@@ -292,6 +292,7 @@ time_min virtualTime;
time_min clockTime;
static long GMToff;
+int stay_foreground;
int lsbsysinit_mode;
char cron_default_mail_charset[MAX_ENVSTR] = "";
|