* `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"
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) );
/* 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;
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 {
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);
}
* `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
* `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);
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)
{
short int i = 0;
int pid;
- CL *line = NULL;
//
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;
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)) {
* `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);
/* 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 */
/* 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 */
test_jobs(now);
+ if ( serial_running == 0)
+ run_serial_job();
+
if ( save - now <= SAVE_VARIATION ) {
save = now + SAVE;
/* save all files */
* `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__
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;
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 */
* `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 $ */
/*
#define FILEVERSION "005" /* syntax's version of fcrontabs :
* must have a length of 3 characters */
+#define ERR -1
+#define OK 0
/* macros */
* `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"
{
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() ) {