diff -ruN ../cron-3.0.1.orig/cron.8 ./cron.8 --- ../cron-3.0.1.orig/cron.8 1994-01-20 21:45:09.000000000 +0300 +++ ./cron.8 2004-05-11 15:19:51.000000000 +0400 @@ -54,6 +54,10 @@ .IR Crontab (1) command updates the modtime of the spool directory whenever it changes a crontab. +.PP +When option '-f' is used +.I cron +will not fork automatically. This allow to run it from /etc/inittab. .SH "SEE ALSO" crontab(1), crontab(5) .SH AUTHOR diff -ruN ../cron-3.0.1.orig/cron.c ./cron.c --- ../cron-3.0.1.orig/cron.c 2004-05-11 15:46:30.000000000 +0400 +++ ./cron.c 2004-05-11 15:59:59.000000000 +0400 @@ -47,7 +47,7 @@ static void usage() { - fprintf(stderr, "usage: %s [-x debugflag[,...]]\n", ProgramName); + fprintf(stderr, "usage: %s [-f][-x debugflag[,...]]\n", ProgramName); exit(ERROR_EXIT); } @@ -60,6 +60,7 @@ cron_db database; ProgramName = argv[0]; + NoFork=0; #if defined(BSD) setlinebuf(stdout); @@ -92,12 +93,30 @@ # endif (void) fprintf(stderr, "[%d] cron started\n", getpid()); } else { - switch (fork()) { - case -1: + if( NoFork ){ + /* main process in nofork mode */ + log_it("CRON",getpid(),"STARTUP","nofork ok"); + (void) setsid(); + { + int fd = open("/dev/null", O_RDWR); + if (fd >= 0) { + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + close(fd); + } else { + (void) close(0); + (void) close(1); + (void) close(2); + } + } + } else { + switch (fork()) { + case -1: log_it("CRON",getpid(),"DEATH","can't fork"); exit(0); break; - case 0: + case 0: /* child process */ log_it("CRON",getpid(),"STARTUP","fork ok"); (void) setsid(); @@ -115,9 +134,10 @@ } } break; - default: + default: /* parent process should just die */ _exit(0); + } } } @@ -305,14 +325,17 @@ { int argch; - while (EOF != (argch = getopt(argc, argv, "x:"))) { + while (EOF != (argch = getopt(argc, argv, "fx:"))) { switch (argch) { - default: - usage(); + case 'f': + NoFork++; + break; case 'x': if (!set_debug_flags(optarg)) usage(); break; + default: + usage(); } } } diff -ruN ../cron-3.0.1.orig/cron.h ./cron.h --- ../cron-3.0.1.orig/cron.h 1994-01-20 21:45:10.000000000 +0300 +++ ./cron.h 2004-05-11 15:01:27.000000000 +0400 @@ -255,6 +255,7 @@ char *ProgramName; int LineNumber; time_t TargetTime; +int NoFork; # if DEBUGGING int DebugFlags;