From aca6b9532b11b8ec457bfa8d4b65a05d90c4cd61 Mon Sep 17 00:00:00 2001 From: Thibault Godouet Date: Mon, 19 Jun 2000 12:41:43 +0000 Subject: [PATCH] FIRST_SLEEP and SAVE_VARIATION added --- config.h.in | 10 +++++++++- fcron.c | 29 +++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/config.h.in b/config.h.in index b5e1650..269463a 100644 --- a/config.h.in +++ b/config.h.in @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: config.h.in,v 1.5 2000-06-18 13:10:43 thib Exp $ */ + /* $Id: config.h.in,v 1.6 2000-06-19 12:41:43 thib Exp $ */ /* *********************************************************** */ @@ -94,6 +94,14 @@ #define MAX_MSG 150 /* max length of a log message */ +/* *** time *** */ +#define FIRST_SLEEP 60 /* fcron sleep at least this time after startup + * before executing a job, to avoid to run jobs + * during system boot */ +#define SAVE_VARIATION 120 /* if a job is run at less than SAVE_VARIATION + * from normal time to save, save is performed + * after execution of the job. + * This is intended to avoid unneeded wakeups */ /* *** system dependent *** */ diff --git a/fcron.c b/fcron.c index 059dc7f..bf67b5f 100644 --- a/fcron.c +++ b/fcron.c @@ -21,11 +21,11 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcron.c,v 1.15 2000-06-18 15:28:15 thib Exp $ */ + /* $Id: fcron.c,v 1.16 2000-06-19 12:42:32 thib Exp $ */ #include "fcron.h" -char rcs_info[] = "$Id: fcron.c,v 1.15 2000-06-18 15:28:15 thib Exp $"; +char rcs_info[] = "$Id: fcron.c,v 1.16 2000-06-19 12:42:32 thib Exp $"; void main_loop(void); void info(void); @@ -338,11 +338,9 @@ main(int argc, char **argv) if (foreground == 0) { - /* - * close stdin and stdout (stderr normally redirected by caller). + /* close stdin, stdout and stderr. * close unused descriptors - * optional detach from controlling terminal - */ + * optional detach from controlling terminal */ int fd; pid_t pid; @@ -372,14 +370,11 @@ main(int argc, char **argv) close(fd); } - fclose(stdin); - fclose(stdout); - if ( (i = open("/dev/null", O_RDWR)) < 0) die_e("open: /dev/null:"); - dup2(i, 0); - dup2(i, 1); - + close(0); dup2(i, 0); + close(1); dup2(i, 1); + close(2); dup2(i, 2); if(debug_opt) { /* wait until child death and log his return value @@ -451,7 +446,7 @@ void main_loop() /* synchronize save with jobs execution */ save = now + SAVE; - if ( (stime = time_to_sleep(save)) < 60 ) + if ( (stime = time_to_sleep(save)) < FIRST_SLEEP ) /* force first execution after 60 sec : execution of job during system boot time is not what we want */ stime = 60; @@ -463,14 +458,14 @@ void main_loop() gettimeofday(&tv, NULL); usleep( 1000000 - tv.tv_usec ); + now = time(NULL); + if (sig_chld > 0) { wait_chld(); sig_chld = 0; } else if (sig_conf > 0) { - now = time(NULL); - if (sig_conf == 1) /* update configuration */ synchronize_dir("."); @@ -483,11 +478,9 @@ void main_loop() else { debug("\n"); - now = time(NULL); - test_jobs(now); - if ( save - now <= 60 ) { + if ( save - now <= SAVE_VARIATION ) { save = now + SAVE; /* save all files */ save_file(NULL, NULL); -- 2.47.3