From: thib Date: Sun, 11 May 2008 15:04:04 +0000 (+0000) Subject: run_job() now returns an int. It returns ERR if it couldn't fork so as the calling... X-Git-Tag: ver3_0_5~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff6b8a646382a2d496d0cf7ea27c82a62e4b6078;p=fcron run_job() now returns an int. It returns ERR if it couldn't fork so as the calling function can remove the relevant entry from exe_array. Previously the job would have been thought to be running until fcron restart. --- diff --git a/database.c b/database.c index 5786af2..28bc3d6 100644 --- a/database.c +++ b/database.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: database.c,v 1.82 2008-05-11 10:56:28 thib Exp $ */ + /* $Id: database.c,v 1.83 2008-05-11 15:05:51 thib Exp $ */ #include "fcron.h" @@ -43,7 +43,7 @@ void run_queue_job(cl_t *line); void resize_exe_array(void); -#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) +#if ! defined(HAVE_SETENV) || ! defined(HAVE_UNSETENV) char env_tz[PATH_LEN]; #endif @@ -283,8 +283,15 @@ run_queue_job(cl_t *line) resize_exe_array(); exe_array[exe_num].e_line = line; - - run_job(&exe_array[exe_num++]); + exe_num++; + + /* run the job */ + if ( run_job(&exe_array[exe_num-1]) != OK ) { + /* The job could not be run: remove it from the exe_array */ + exe_array[exe_num-1].e_line->cl_numexe--; + exe_array[exe_num-1].e_line = NULL; + exe_num--; + } } diff --git a/job.c b/job.c index 7830f80..2bc7b88 100644 --- a/job.c +++ b/job.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: job.c,v 1.73 2007-11-07 09:15:02 thib Exp $ */ + /* $Id: job.c,v 1.74 2008-05-11 15:04:04 thib Exp $ */ #include "fcron.h" @@ -428,9 +428,10 @@ run_job_grand_child_setup_env_var(cl_t *line, char **curshell) } } -void +int run_job(struct exe_t *exeent) - /* fork(), redirect outputs to a temp file, and execl() the task */ + /* fork(), redirect outputs to a temp file, and execl() the task. + * Return ERR if it could not fork() the first time, OK otherwise. */ { pid_t pid; @@ -452,6 +453,7 @@ run_job(struct exe_t *exeent) switch ( pid = fork() ) { case -1: error_e("Fork error : could not exec \"%s\"", line->cl_shell); + return ERR; break; case 0: @@ -498,7 +500,7 @@ run_job(struct exe_t *exeent) #ifndef RUN_NON_PRIVILEGED if (change_user(line) < 0) - return ; + exit(EXIT_ERR); #endif sig_dfl(); @@ -647,7 +649,8 @@ run_job(struct exe_t *exeent) } - /* execution never gets here */ + /* execution should never gets here, but if it happened we exit with an error */ + exit(EXIT_ERR); } default: @@ -680,12 +683,15 @@ run_job(struct exe_t *exeent) } if ( close(pipe_pid_fd[0]) < 0 ) error_e("parent: could not close(pipe_pid_fd[0])"); - } #ifdef CHECKRUNJOB - debug("run_job(): finished reading pid of the job -- end of run_job()."); + debug("run_job(): finished reading pid of the job -- end of run_job()."); #endif /* CHECKRUNJOB */ + } + + return OK; + } void diff --git a/job.h b/job.h index 5e112d4..a27ac02 100644 --- a/job.h +++ b/job.h @@ -21,14 +21,14 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: job.h,v 1.9 2007-04-14 18:04:09 thib Exp $ */ + /* $Id: job.h,v 1.10 2008-05-11 15:05:35 thib Exp $ */ #ifndef __JOB_H__ #define __JOB_H__ /* functions prototypes */ extern int change_user(struct cl_t *cl); -extern void run_job(struct exe_t *exeent); +extern int run_job(struct exe_t *exeent); extern FILE *create_mail(struct cl_t *line, char *subject); extern void launch_mailer(struct cl_t *line, FILE *mailf);