]> granicus.if.org Git - fcron/commitdiff
the running job are no more chaine-listed
authorthib <thib>
Tue, 20 Jun 2000 20:36:26 +0000 (20:36 +0000)
committerthib <thib>
Tue, 20 Jun 2000 20:36:26 +0000 (20:36 +0000)
we now use an array of pointer of lines, which we make grow up if necessary

database.c
fcron.c
fcron.h
job.c

index 1bc95fb36e1555c496b62bc9f2a09d2510a85603..cf364cc3cc8acaac30da486abccd5889b9ca74b8 100644 (file)
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: database.c,v 1.11 2000-06-19 12:42:16 thib Exp $ */
+ /* $Id: database.c,v 1.12 2000-06-20 20:36:26 thib Exp $ */
 
 #include "fcron.h"
 
@@ -42,7 +42,7 @@ test_jobs(time_t t2)
 
     while ( (j=queue_base) && j->j_line->cl_nextexe <= t2 ){
        set_next_exe(j->j_line, 0);
-       if ( j->j_line->cl_remain > 0 && (j->j_line->cl_remain)-- > 0) {
+       if ( j->j_line->cl_remain > 0 && --(j->j_line->cl_remain) > 0) {
            debug("    cl_remain: %d", j->j_line->cl_remain);
            continue ;
        }
@@ -66,27 +66,34 @@ void
 wait_chld(void)
   /* wait_chld() - check for job completion */
 {
-    struct job *j;
-    struct job *jprev = NULL;
+    short int i = 0;
     int pid;
+    CL *line = NULL;
 
-    while ( (pid = wait3(NULL, WNOHANG, NULL)) > 0 ) {
-       for (j = exe_base; j != NULL ; j = j->j_next) {
-           if (pid < 0 || pid == j->j_line->cl_pid) {
-               j->j_line->cl_pid = 0;
-               j->j_line->cl_file->cf_running -= 1;
 
-               /* remove file from exe list */
-               if (jprev != NULL)
-                   jprev->j_next = j->j_next;
+//
+    debug("wait_chld");
+//
+    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) {
+               exe_array[i]->cl_pid = 0;
+               exe_array[i]->cl_file->cf_running -= 1;
+               if (i < --exe_num) {
+                   exe_array[i] = exe_array[exe_num];
+                   exe_array[exe_num] = NULL;
+               }
                else
-                   exe_base = j->j_next;
-               free(j);
-               
+                   exe_array[i] = NULL;
+
                goto nextloop;
            }
-           jprev = j;
-       }       
+           i++;
+       }
+       /* execution shouldn't come here */
+       error("not in exe_array !");
       nextloop:
     }
 
@@ -97,30 +104,30 @@ void
 wait_all(int *counter)
    /* return after all jobs completion. */
 {
-    struct job *j;
-    struct job *jprev = NULL;
+    short int i = 0;
     int pid;
 
     debug("Waiting for all jobs");
 
     while ( (*counter > 0) && (pid = wait3(NULL, 0, NULL)) > 0 ) {
-       for (j = exe_base; j != NULL ; j = j->j_next) {
-           if (pid < 0 || pid == j->j_line->cl_pid) {
-
-               j->j_line->cl_pid = 0;
-               j->j_line->cl_file->cf_running -= 1;
-
-               /* remove file from exe list */
-               if (jprev != NULL)
-                   jprev->j_next = j->j_next;
+       i = 0;
+       while ( i < exe_array_size ) {
+           if (pid == exe_array[i]->cl_pid) {
+               exe_array[i]->cl_pid = 0;
+               exe_array[i]->cl_file->cf_running -= 1;
+               if (i < --exe_num) {
+                   exe_array[i] = exe_array[exe_num];
+                   exe_array[exe_num] = NULL;
+               }
                else
-                   exe_base = j->j_next;
-               free(j);
-               
+                   exe_array[i] = NULL;
+
                goto nextloop;
            }
-           jprev = j;
+           i++;
        }
+       /* execution shouldn't come here */
+       error("not in exe_array !");
       nextloop:
     }    
 
diff --git a/fcron.c b/fcron.c
index bf67b5f3d26065a91556f9e2386d85bba52befed..118c9fa1bdc8cd97a408d1aa897d33cb861c32be 100644 (file)
--- a/fcron.c
+++ b/fcron.c
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.c,v 1.16 2000-06-19 12:42:32 thib Exp $ */
+ /* $Id: fcron.c,v 1.17 2000-06-20 20:37:51 thib Exp $ */
 
 #include "fcron.h"
 
-char rcs_info[] = "$Id: fcron.c,v 1.16 2000-06-19 12:42:32 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.17 2000-06-20 20:37:51 thib Exp $";
 
 void main_loop(void);
 void info(void);
@@ -55,7 +55,9 @@ char sig_chld = 0;            /* is 1 when we got a SIGCHLD */
 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 job *exe_base;         /* jobs which are executed */
+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 */
 
 time_t begin_sleep;           /* the time at which sleep began */
 time_t now;                   /* the current time */
@@ -421,6 +423,12 @@ main(int argc, char **argv)
     (void)signal(SIGUSR1, sigusr1_handler);
     siginterrupt(SIGUSR1, 0);
 
+
+    /* initialize exe_array */
+    exe_array_size = EXE_ARRAY_INITIAL_SIZE;
+    if ( (exe_array = calloc(exe_array_size, sizeof(CL *))) == NULL )
+       die_e("could not calloc exe_array");
+
     main_loop();
 
     /* never reached */
@@ -447,9 +455,9 @@ void main_loop()
     save = now + SAVE;
 
     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;
+       /* force first execution after FIRST_SLEEP sec : execution of jobs
+        * during system boot time is not what we want */
+       stime = FIRST_SLEEP;
     
 
     for (;;) {
diff --git a/fcron.h b/fcron.h
index c9e59c7bc7d1f7f6783cd5fdf7e3d20cb45a0d4d..b9ad61cbd81b58d7024c3ed576a001fd328ee92d 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.7 2000-06-15 20:16:38 thib Exp $ */
+ /* $Id: fcron.h,v 1.8 2000-06-20 20:38:30 thib Exp $ */
 
 #ifndef __FCRONH__
 #define __FCRONH__
@@ -36,6 +36,7 @@
 
 
 /* global variables */
+extern time_t now;
 extern char debug_opt;
 extern char foreground;
 extern char *cdir;
@@ -46,8 +47,9 @@ extern char sig_hup;
 extern CF *file_base;
 extern struct job *queue_base;
 extern struct job *serial_base;
-extern struct job *exe_base;
-extern time_t now;
+extern struct CL **exe_array;
+extern short int exe_array_size;
+extern short int exe_num;
 /* end of global variables */
 
 
diff --git a/job.c b/job.c
index 1d0dd4a5b66fc731b5fd6c08c0b311d9aa03964b..6af9096e3da8cd4b025bd04057f021c6fd3ceb4b 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.10 2000-06-19 12:43:27 thib Exp $ */
+ /* $Id: job.c,v 1.11 2000-06-20 20:38:45 thib Exp $ */
 
 #include "fcron.h"
 
@@ -81,13 +81,24 @@ run_job(CL *line)
 {
 
     pid_t pid;
-    struct job *j;
+    short int i = 0;
 
     /* append job to the list of executed job */
-    Alloc(j, job);
-    j->j_line = line;
-    j->j_next = exe_base;
-    exe_base = j;
+    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() ) {
@@ -240,7 +251,7 @@ end_job(CL *line, int status, int mailfd, short mailpos)
 
     if (mail_output == 1) launch_mailer(line, mailfd);
 
-    /* if MAILTO is "", temp file is already closed */
+    /* if mail is sent, execution doesn't get here : close /dev/null */
     if ( close(mailfd) != 0 )
        die_e("Can't close file descriptor %d", mailfd);