]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
support of bootrun and serialize
authorThibault Godouet <yo8192@users.noreply.github.com>
Wed, 21 Jun 2000 09:48:26 +0000 (09:48 +0000)
committerThibault Godouet <yo8192@users.noreply.github.com>
Wed, 21 Jun 2000 09:48:26 +0000 (09:48 +0000)
conf.c
config.h.in
database.c
fcron.c
fcron.h
global.h
job.c

diff --git a/conf.c b/conf.c
index 971b5d13edbbc06be4749c01474c44ecfe353616..0f9a0063f11e8a22f33d3954e40f8b2d5c4c4a4d 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: conf.c,v 1.10 2000-06-19 12:41:27 thib Exp $ */
+ /* $Id: conf.c,v 1.11 2000-06-21 09:48:26 thib Exp $ */
 
 #include "fcron.h"
 
@@ -216,8 +216,7 @@ synchronize_file(char *file_name)
            CL *new_l = NULL;
            /* size used when comparing two line : 
             * it's the size of all time table (mins, days ...) */
-           const size_t size=( sizeof(time_t) + sizeof(short int) + 
-                               bitstr_size(60) + bitstr_size(24) + 
+           const size_t size=( bitstr_size(60) + bitstr_size(24) + 
                                bitstr_size(32) + bitstr_size(12) +
                                bitstr_size(7) );
            
@@ -253,10 +252,13 @@ synchronize_file(char *file_name)
 
                    /* compare the shell command and the fields 
                       from cl_mins down to cl_runfreq or the timefreq */
-                   if ( strcmp(new_l->cl_shell, old_l->cl_shell) == 0 &&
-                        memcmp( &(new_l->cl_timefreq), &(old_l->cl_timefreq),
-                                size)==0
-                       ) {
+                   if ( strcmp(new_l->cl_shell, old_l->cl_shell) == 0 && (
+                       ( is_freq(new_l->cl_option) && 
+                         new_l->cl_timefreq == old_l->cl_timefreq ) ||
+                       ( is_td(new_l->cl_option) &&
+                         memcmp( &(new_l->cl_mins), &(old_l->cl_mins),
+                                 size)==0 )
+                       ) ) {
                        
                        new_l->cl_remain = old_l->cl_remain;
                        new_l->cl_nextexe = old_l->cl_nextexe;
@@ -449,8 +451,11 @@ read_file(const char *file_name, CF *cf)
 
        if ( is_td(cl->cl_option) ) {
            /* set the time and date of the next execution  */
-           if ( cl->cl_nextexe <= now )
+           if ( cl->cl_nextexe <= now ) {
+               if ( is_bootrun(cl->cl_option) )
+                   add_serial_job(cl);
                set_next_exe(cl, 1);
+           }
            else
                insert_nextexe(cl);
        } else {
@@ -458,17 +463,17 @@ read_file(const char *file_name, CF *cf)
            insert_nextexe(cl);
        }           
 
+       if ( cl->cl_pid == -1)
+           add_serial_job(cl);
+
        /* check if the task has not been stopped during execution */
        if (cl->cl_pid > 0) {
            /* job has been stopped during execution :
             * launch it again */
            warn("job '%s' has not terminated : will be executed"
                 " again now.", cl->cl_shell);
-           /* we don't set cl_nextexe to 0 because this value is 
-            * reserved to the entries based on frequency */
-           cl->cl_nextexe = 1;
-           insert_nextexe(cl);
            cl->cl_pid = 0;
+           add_serial_job(cl);
        }
            
 
index 090b3942d9e76800bd271166fc404e109aed806e..20daf385e1961ae252f9bcd32d4314e5a78921f8 100644 (file)
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: config.h.in,v 1.7 2000-06-20 20:36:19 thib Exp $ */
+ /* $Id: config.h.in,v 1.8 2000-06-21 09:48:36 thib Exp $ */
 
 
 /* *********************************************************** */
 #endif
 
 
+
+/* *** system dependent *** */
+#define EXIT_ERR   1         /* code returned by fcron/fcrontab on error */
+#define EXIT_OK    0         /* code returned  on normal exit */
+
+
 /* *** paths *** */
 
 #define FCRON_ALLOW      "fcron.allow"
 
 
 /* *** memory *** */
-
-#define EXE_ARRAY_INITIAL_SIZE 10 /* initial number of possible running job 
-                                  * if more job have to be run simultaneously,
-                                  * fcron will have to perform a realloc() */
-#define EXE_ARRAY_GROW_SIZE 10 /* this is the number of entries that will be
-                               * added to exe_array each time it has to grow
-                               * up */
+#define EXE_ARRAY_INITIAL_SIZE 6 /* initial number of possible running job 
+                                 * if more jobs have to be run simultaneously,
+                                 * fcron will have to calloc() more memory */
+#define EXE_ARRAY_GROW_SIZE 5 /* this is the number of entries that will be
+                              * added to exe_array each time it has to grow
+                              * up */
 
 #define MAXENTRIES  256  /* max lines in non-root fcrontabs */
 
                             * after execution of the job.
                             * This is intended to avoid unneeded wakeups */
 
-/* *** system dependent *** */
 
-#define ERR     -1           
-#define OK       0
+/* *** behavior *** */
+#define SERIAL_QUEUE_MAX 30 /* if serial queue contains this number of entries,
+                            * the next serial job to be executed will be run
+                            * non-serially each time a serial job is added */
+#define SERIAL_INITIAL_SIZE 10 /* initial number of possible serial job. If
+                               * more jobs have to be in queuesimultaneously,
+                               * fcron will have to calloc() more memory */
+#define SERIAL_GROW_SIZE 10 /* this is the number of entries that will be
+                            * added to serial queue each time it has to grow
+                            * up */
 
-#define EXIT_ERR   1         /* code returned by fcron/fcrontab on error */
-#define EXIT_OK    0         /* code returned  on normal exit */
 
 /* Syslog facility and priorities messages will be logged to (see syslog(3)) */
 #define SYSLOG_FACILITY LOG_CRON
index cf364cc3cc8acaac30da486abccd5889b9ca74b8..82af3486e21f784ebb6cfb369f1febbec5f6c3ca 100644 (file)
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: database.c,v 1.12 2000-06-20 20:36:26 thib Exp $ */
+ /* $Id: database.c,v 1.13 2000-06-21 09:48:54 thib Exp $ */
 
 #include "fcron.h"
 
 int is_leap_year(int year);
 int get_nb_mdays(int year, int mon);
 void goto_non_matching(CL *line, struct tm *tm);
+void run_serial_job(void);
+void run_queue_job(CL *line);
 
 
 
@@ -55,12 +57,99 @@ test_jobs(time_t t2)
                 j->j_line->cl_shell
                );
        } 
+       else if ( is_serial(j->j_line->cl_option) )
+           add_serial_job(j->j_line);
        else
-           run_job(j->j_line);
+           run_queue_job(j->j_line);
     }
 
 }
 
+void
+add_serial_job(CL *line)
+    /* add the next queued job in serial queue */
+{
+    short int i;
+
+    if ( line->cl_pid != -1 ) {
+       line->cl_pid = -1;
+       serial_num++;
+
+       if ( serial_num > serial_array_size ) {
+           CL **ptr = NULL;
+           short int old_size = serial_array_size;
+
+           debug("Resizing serial_array");
+           serial_array_size = (serial_array_size + SERIAL_GROW_SIZE);
+       
+           if ( (ptr = calloc(serial_array_size, sizeof(CL *))) == NULL )
+               die_e("could not calloc serial_array");
+
+           memcpy(ptr, serial_array, (sizeof(CL *) * old_size));
+           free(serial_array);
+           serial_array = ptr;
+       }
+           
+       if ( (i = serial_array_index + serial_num) >= serial_array_size )
+           i -= serial_array_size;
+       serial_array[i] = line;
+
+    }
+
+    else {
+       /* job is already in serial queue : advance his execution */
+
+       ///////////////
+       // Put the corresponding code
+       //////////////
+
+    }
+
+}
+
+
+void
+run_serial_job(void)
+    /* run the next serialized job */
+{
+    if ( serial_num != 0 ) {
+       run_job(serial_array[serial_array_index]);
+
+       serial_running++;
+       serial_array_index++;
+       serial_num--;
+       
+    }
+}
+                   
+
+void
+run_queue_job(CL *line)
+    /* run the next non-serialized job */
+{
+
+    /* append job to the list of executed job */
+    if ( exe_num >= exe_array_size ) {
+       CL **ptr = NULL;
+       short int old_size = exe_array_size;
+
+       debug("Resizing exe_array");
+       exe_array_size = (exe_array_size + EXE_ARRAY_GROW_SIZE);
+       
+       if ( (ptr = calloc(exe_array_size, sizeof(CL *))) == NULL )
+           die_e("could not calloc exe_array");
+
+       memcpy(ptr, exe_array, (sizeof(CL *) * old_size));
+       free(exe_array);
+       exe_array = ptr;
+    }
+    exe_array[exe_num++] = line;
+
+    run_job(line);
+
+}
+
+
 
 void
 wait_chld(void)
@@ -68,7 +157,6 @@ wait_chld(void)
 {
     short int i = 0;
     int pid;
-    CL *line = NULL;
 
 
 //
@@ -77,10 +165,13 @@ wait_chld(void)
     while ( (pid = wait3(NULL, WNOHANG, NULL)) > 0 ) {
        i = 0;
        while ( i < exe_array_size ) {
-           line = exe_array[i];
-           if (line != NULL && pid == line->cl_pid) {
+           if (exe_array[i] != NULL && pid == exe_array[i]->cl_pid) {
                exe_array[i]->cl_pid = 0;
                exe_array[i]->cl_file->cf_running -= 1;
+
+               if(is_serial(exe_array[i]->cl_option) && --serial_running == 0)
+                   run_serial_job();
+                   
                if (i < --exe_num) {
                    exe_array[i] = exe_array[exe_num];
                    exe_array[exe_num] = NULL;
@@ -397,7 +488,10 @@ insert_nextexe(CL *line)
 
                break;
            }
+           else
+               jprev = j;
 
+       jprev = NULL;
        if (j == NULL || line->cl_nextexe < j->j_line->cl_nextexe)
            j = queue_base;
        while (j != NULL && (line->cl_nextexe >= j->j_line->cl_nextexe)) {
diff --git a/fcron.c b/fcron.c
index 118c9fa1bdc8cd97a408d1aa897d33cb861c32be..13d8ca41298b75d128fda9bae8555f59ae4633fe 100644 (file)
--- a/fcron.c
+++ b/fcron.c
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.c,v 1.17 2000-06-20 20:37:51 thib Exp $ */
+ /* $Id: fcron.c,v 1.18 2000-06-21 09:48:56 thib Exp $ */
 
 #include "fcron.h"
 
-char rcs_info[] = "$Id: fcron.c,v 1.17 2000-06-20 20:37:51 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.18 2000-06-21 09:48:56 thib Exp $";
 
 void main_loop(void);
 void info(void);
@@ -54,7 +54,11 @@ char sig_chld = 0;            /* is 1 when we got a SIGCHLD */
 /* jobs database */
 struct CF *file_base;         /* point to the first file of the list */
 struct job *queue_base;       /* ordered list of normal jobs to be run */
-struct job *serial_base;      /* ordered list of job to be run one by one */
+struct CL **serial_array;     /* ordered list of job to be run one by one */
+short int serial_array_size;  /* size of serial_base array */
+short int serial_array_index; /* the index of the first job */
+short int serial_num;         /* number of job being queued */
+short int serial_running;     /* number of running serial jobs */
 struct CL **exe_array;        /* jobs which are executed */
 short int exe_array_size;     /* size of exe_array */
 short int exe_num;            /* number of job being executed */
@@ -425,10 +429,20 @@ main(int argc, char **argv)
 
 
     /* initialize exe_array */
+    exe_num = 0;
     exe_array_size = EXE_ARRAY_INITIAL_SIZE;
     if ( (exe_array = calloc(exe_array_size, sizeof(CL *))) == NULL )
        die_e("could not calloc exe_array");
 
+    /* initialize serial_array */
+    serial_running = 0;
+    serial_array_index = 0;
+    serial_num = 0;
+    serial_array_size = SERIAL_INITIAL_SIZE;
+    if ( (serial_array = calloc(serial_array_size, sizeof(CL *))) == NULL )
+       die_e("could not calloc serial_array");
+
+
     main_loop();
 
     /* never reached */
@@ -488,6 +502,9 @@ void main_loop()
 
            test_jobs(now);
 
+           if ( serial_running == 0)
+               run_serial_job();
+
            if ( save - now <= SAVE_VARIATION ) {
                save = now + SAVE;
                /* save all files */
diff --git a/fcron.h b/fcron.h
index b9ad61cbd81b58d7024c3ed576a001fd328ee92d..3484663e1b55d3fd54b98b6a7a863f4444f86ca7 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.8 2000-06-20 20:38:30 thib Exp $ */
+ /* $Id: fcron.h,v 1.9 2000-06-21 09:48:58 thib Exp $ */
 
 #ifndef __FCRONH__
 #define __FCRONH__
@@ -46,7 +46,11 @@ extern char *prog_name;
 extern char sig_hup;
 extern CF *file_base;
 extern struct job *queue_base;
-extern struct job *serial_base;
+extern struct CL **serial_array;
+extern short int serial_array_size;
+extern short int serial_array_index;
+extern short int serial_num;
+extern short int serial_running;
 extern struct CL **exe_array;
 extern short int exe_array_size;
 extern short int exe_num;
@@ -85,6 +89,8 @@ extern void wait_all(int *counter);
 extern time_t time_to_sleep(time_t lim);
 extern void set_next_exe(CL *line, char is_new_line);
 extern void insert_nextexe(CL *line);
+extern void add_serial_job(CL *line);
+extern void run_serial_job(void);
 /* end of database.c */
 
 /* conf.c */
index fe8dc4f2576a26dd6c7892a3f7817e050d262484..213e3c9a06690ff4ff2af42b7e44a4034a3de1ba 100644 (file)
--- a/global.h
+++ b/global.h
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: global.h,v 1.9 2000-06-19 12:43:11 thib Exp $ */
+ /* $Id: global.h,v 1.10 2000-06-21 09:48:59 thib Exp $ */
 
 
 /* 
@@ -60,6 +60,8 @@
 #define FILEVERSION "005"  /* syntax's version of fcrontabs : 
                            * must have a length of 3 characters */
 
+#define ERR     -1           
+#define OK       0
 
 
 /* macros */
diff --git a/job.c b/job.c
index 6af9096e3da8cd4b025bd04057f021c6fd3ceb4b..7063ff093b4e3ec85586c96af81ce5ee30c13397 100644 (file)
--- a/job.c
+++ b/job.c
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: job.c,v 1.11 2000-06-20 20:38:45 thib Exp $ */
+ /* $Id: job.c,v 1.13 2000-06-21 09:50:09 thib Exp $ */
 
 #include "fcron.h"
 
@@ -81,24 +81,6 @@ run_job(CL *line)
 {
 
     pid_t pid;
-    short int i = 0;
-
-    /* append job to the list of executed job */
-    if ( exe_num >= exe_array_size ) {
-       CL **ptr = NULL;
-       short int old_size = exe_array_size;
-
-       debug("Resizing exe_array");
-       exe_array_size = (exe_array_size + EXE_ARRAY_GROW_SIZE);
-       
-       if ( (ptr = calloc(exe_array_size, sizeof(CL *))) == NULL )
-           die_e("could not calloc exe_array");
-
-       memcpy(ptr, exe_array, (sizeof(CL *) * old_size));
-       free(exe_array);
-       exe_array = ptr;
-    }
-    exe_array[exe_num++] = line;
 
     /* prepare the job execution */
     switch ( pid = fork() ) {