]> granicus.if.org Git - fcron/commitdiff
added options -y, -l, -o
authorthib <thib>
Mon, 25 Feb 2002 18:41:24 +0000 (18:41 +0000)
committerthib <thib>
Mon, 25 Feb 2002 18:41:24 +0000 (18:41 +0000)
fcron.c
fcron.h

diff --git a/fcron.c b/fcron.c
index 51b3db8633301c07c8c57d0500b871f77a88d999..ccdb534332ea8c454709cbf509aaa4757c4f41ab 100644 (file)
--- a/fcron.c
+++ b/fcron.c
  *  `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);
@@ -60,7 +61,11 @@ char foreground = 1; /* set to 1 when we are on foreground, else 0 */
 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 = "";
@@ -130,15 +135,21 @@ usage(void)
            "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);
@@ -258,9 +269,12 @@ parseopt(int argc, char *argv[])
        {"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'},
@@ -275,9 +289,9 @@ parseopt(int argc, char *argv[])
 
     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) {
@@ -297,12 +311,22 @@ parseopt(int argc, char *argv[])
        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 )
@@ -625,16 +649,18 @@ main_loop()
     /* 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);
@@ -654,6 +680,11 @@ main_loop()
        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 */
@@ -661,7 +692,7 @@ main_loop()
        }
 
        stime = check_lavg(save);
-       debug("sleep time : %ld", stime);
+       debug("next sleep time : %ld", stime);
 
        check_signal();
 
diff --git a/fcron.h b/fcron.h
index 9d67cb78526b73ac1a263e68b613877e2d94c65e..c0303c672d32d3cea899f59085814e6654e39608 100644 (file)
--- a/fcron.h
+++ b/fcron.h
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.h,v 1.25 2001-12-23 22:04:41 thib Exp $ */
+ /* $Id: fcron.h,v 1.26 2002-02-25 18:41:47 thib Exp $ */
 
 #ifndef __FCRON_H__
 #define __FCRON_H__
@@ -58,6 +58,8 @@
 extern time_t now;
 extern char debug_opt;
 extern char foreground;
+extern char dosyslog;
+extern time_t first_sleep;
 extern char *cdir;
 extern pid_t daemon_pid;
 extern mode_t saved_umask;