* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcron.c,v 1.59 2002-02-24 16:50:14 thib Exp $ */
+ /* $Id: fcron.c,v 1.60 2002-02-25 18:41:24 thib Exp $ */
#include "fcron.h"
#include "database.h"
#include "conf.h"
#include "job.h"
+#include "temp_file.h"
-char rcs_info[] = "$Id: fcron.c,v 1.59 2002-02-24 16:50:14 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.60 2002-02-25 18:41:24 thib Exp $";
void main_loop(void);
void check_signal(void);
char foreground = 0; /* set to 1 when we are on foreground, else 0 */
#endif
+time_t first_sleep = FIRST_SLEEP;
time_t save_time = SAVE;
+char once = 0; /* set to 1 if fcron shall return immediately after running
+ * all jobs that are due at the time when fcron is started */
+char dosyslog = 1; /* set to 1 when we log messages to syslog, else 0 */
/* used in temp_file() : create it in current dir (normally spool dir) */
char *tmp_path = "";
"fcron [-d] [-f] [-b]\n"
"fcron -h\n"
" -s t --savetime t Save fcrontabs on disk every t sec.\n"
- " -m n --maxserial n Set to n the max number of running "
- "serial jobs.\n"
+ " -l t --firstsleep t Sets the initial delay before any job is executed"
+ ",\n default to %d seconds.\n"
+ " -m n --maxserial n Set to n the max number of running serial jobs.\n"
" -c f --configfile f Make fcron use config file f.\n"
" -n d --newspooldir d Create d as a new spool directory.\n"
" -d --debug Set Debug mode.\n"
" -f --foreground Stay in foreground.\n"
" -b --background Go to background.\n"
+ " -y --nosyslog Don't log to syslog at all.\n"
+ " -o --once Execute all jobs that need to be run, wait for "
+ "them,\n then return. Sets firstsleep to 0.\n"
+ " Especially useful with -f and -y.\n"
" -h --help Show this help message.\n"
- " -V --version Display version & infos about fcron.\n"
+ " -V --version Display version & infos about fcron.\n",
+ FIRST_SLEEP
);
exit(EXIT_ERR);
{"debug", 0, NULL, 'd'},
{"foreground", 0, NULL, 'f'},
{"background", 0, NULL, 'b'},
+ {"nosyslog", 0, NULL, 'y'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
+ {"once", 0, NULL, 'o'},
{"savetime", 1, NULL, 's'},
+ {"firstsleep", 1, NULL, 'l'},
{"maxserial", 1, NULL, 'm'},
{"configfile", 1, NULL, 'c'},
{"newspooldir", 1, NULL, 'n'},
while(1) {
#ifdef HAVE_GETOPT_LONG
- c = getopt_long(argc, argv, "dfbhVs:m:c:n:", opt, NULL);
+ c = getopt_long(argc, argv, "dfbyhVos:l:m:c:n:", opt, NULL);
#else
- c = getopt(argc, argv, "dfbhVs:m:c:n:");
+ c = getopt(argc, argv, "dfbyhVos:l:m:c:n:");
#endif /* HAVE_GETOPT_LONG */
if ( c == EOF ) break;
switch (c) {
case 'b':
foreground = 0; break;
+ case 'y':
+ dosyslog = 0; break;
+
+ case 'o':
+ once = 1; first_sleep = 0; break;
+
case 's':
- if ( (save_time = strtol(optarg, NULL, 10)) < 60
- || save_time >= LONG_MAX )
+ if ( (save_time = strtol(optarg, NULL, 10)) < 60 || save_time >= LONG_MAX )
die("Save time can only be set between 60 and %d.", LONG_MAX);
break;
+ case 'l':
+ if ( (first_sleep = strtol(optarg, NULL, 10)) < 0 || first_sleep >= LONG_MAX)
+ die("First sleep can only be set between 0 and %d.", LONG_MAX);
+ break;
+
case 'm':
if ( (serial_max_running = strtol(optarg, NULL, 10)) <= 0
|| serial_max_running >= SHRT_MAX )
/* synchronize save with jobs execution */
save = now + save_time;
- if ( serial_num > 0 )
- stime = FIRST_SLEEP;
- else if ( (stime = time_to_sleep(save)) < FIRST_SLEEP )
- /* force first execution after FIRST_SLEEP sec : execution of jobs
+ if ( serial_num > 0 || once )
+ stime = first_sleep;
+ else if ( (stime = time_to_sleep(save)) < first_sleep )
+ /* force first execution after first_sleep sec : execution of jobs
* during system boot time is not what we want */
- stime = FIRST_SLEEP;
-
+ stime = first_sleep;
for (;;) {
+ /* */
+ debug("sleep %ld seconds", stime);
+ /* */
#ifdef HAVE_GETTIMEOFDAY
if (stime > 1)
sleep(stime - 1);
while ( serial_num > 0 && serial_running < serial_max_running )
run_serial_job();
+ if ( once ) {
+ explain("Running with option once : exiting ... (SIGTERM raise()d)");
+ raise(SIGTERM);
+ }
+
if ( save <= now ) {
save = now + save_time;
/* save all files */
}
stime = check_lavg(save);
- debug("sleep time : %ld", stime);
+ debug("next sleep time : %ld", stime);
check_signal();