* `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"
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 ;
}
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:
}
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:
}
* `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);
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 */
(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 */
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 (;;) {
* `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__
/* global variables */
+extern time_t now;
extern char debug_opt;
extern char foreground;
extern char *cdir;
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 */
* `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"
{
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() ) {
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);