]> granicus.if.org Git - fcron/commitdiff
rewrite of the management of the output of jobs
authorthib <thib>
Fri, 19 Jul 2002 19:32:28 +0000 (19:32 +0000)
committerthib <thib>
Fri, 19 Jul 2002 19:32:28 +0000 (19:32 +0000)
database.c
fcron.c
job.h

index f3aedbdadaa8de0d647d6576d6ca8577d65d9c91..cd478125979cadceb08d18d80dba15dd96cf3c63 100644 (file)
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: database.c,v 1.62 2002-02-25 18:43:54 thib Exp $ */
+ /* $Id: database.c,v 1.63 2002-07-19 19:38:56 thib Exp $ */
 
 #include "fcron.h"
 
@@ -1047,9 +1047,8 @@ mail_notrun(CL *line, char context, struct tm *since)
     /* send a mail to tell user a job has not run (and why) */
 {
     int pid = 0;
-    int fd = 0;
+    FILE *mailf = 0;
     struct tm *time2 = NULL, time;
-    char buf[LINE_LEN];
 
     switch ( pid = fork() ) {
     case -1:
@@ -1083,46 +1082,38 @@ mail_notrun(CL *line, char context, struct tm *since)
     memcpy(&time, time2, sizeof(time));
 
     /* create a temp file, and write in it the message to send */
-    fd = create_mail(line, "Non-execution of fcron job");
+    mailf = create_mail(line, "Non-execution of fcron job");
 
     switch ( context ) {
     case SYSDOWN:
-       snprintf(buf, sizeof(buf), "Line %s has not run since and including "
+       fprintf(mailf, "Line %s has not run since and including "
                 "%d/%d/%d wday:%d %02d:%02d\ndue to system's down state.\n",
                 line->cl_shell, (since->tm_mon + 1), since->tm_mday,
                 (since->tm_year + 1900), since->tm_wday, since->tm_hour,
                 since->tm_min);
-       xwrite(fd, buf);
-       snprintf(buf,sizeof(buf),"It will be next executed at %d/%d/%d wday:"
+       fprintf(mailf, "It will be next executed at %d/%d/%d wday:"
                 "%d %02d:%02d\n", (time.tm_mon + 1), time.tm_mday,
                 (time.tm_year+1900), time.tm_wday, time.tm_hour, time.tm_min);
-       xwrite(fd, buf);
        break;
     case LAVG:
-       snprintf(buf, sizeof(buf), "Line %s has not run since and including "
+       fprintf(mailf, "Line %s has not run since and including "
                 "%d/%d/%d wday:%d %02d:%02d\n", line->cl_shell,
                 (since->tm_mon + 1), since->tm_mday, (since->tm_year + 1900),
                 since->tm_wday, since->tm_hour, since->tm_min);
-       xwrite(fd, buf);
-       snprintf(buf, sizeof(buf), "due to a too high system load average or "
+       fprintf(mailf, "due to a too high system load average or "
                 "too many lavg-serial jobs.\n");
-       xwrite(fd, buf);        
-       snprintf(buf, sizeof(buf), "It will be next executed at %d/%d/%d "
+       fprintf(mailf, "It will be next executed at %d/%d/%d "
                 "wday:%d %02d:%02d\n", (time.tm_mon + 1), time.tm_mday,
                 (time.tm_year+1900), time.tm_wday, time.tm_hour, time.tm_min);
-       xwrite(fd, buf);
        break;
     case QUEUE_FULL:
-       snprintf(buf, sizeof(buf), "Line %s could be added to lavg or serial queue which"
+       fprintf(mailf, "Line %s could be added to lavg or serial queue which"
                 " is full ( %d/%d/%d wday:%d %02d:%02d ).\n", line->cl_shell,
                 (time.tm_mon + 1), time.tm_mday, (time.tm_year + 1900),
                 time.tm_wday, time.tm_hour, time.tm_min);
-       xwrite(fd, buf);
-       snprintf(buf, sizeof(buf), "Consider using options lavgonce, until, strict, "
+       fprintf(mailf, "Consider using options lavgonce, until, strict, "
                 "serialonce and/or fcron's option -m.\n");
-       xwrite(fd, buf);
-       snprintf(buf, sizeof(buf), "Note that job %s has not run.\n", line->cl_shell);
-       xwrite(fd, buf);
+       fprintf(mailf, "Note that job %s has not run.\n", line->cl_shell);
        break;
     }
     
@@ -1131,7 +1122,7 @@ mail_notrun(CL *line, char context, struct tm *since)
        return ;
 
     /* then, send mail */
-    launch_mailer(line, fd);
+    launch_mailer(line, mailf);
     
     /* we should not come here : launch_mailer does not return */
     error("mail_notrun : launch_mailer failed");
diff --git a/fcron.c b/fcron.c
index fde5c5105e7b1a0d2f6002ca4b40a73259f66330..a307507f081a1f9d7e9022bb0286513abf5bfa17 100644 (file)
--- a/fcron.c
+++ b/fcron.c
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fcron.c,v 1.63 2002-03-31 17:20:35 thib Exp $ */
+ /* $Id: fcron.c,v 1.64 2002-07-19 19:36:10 thib Exp $ */
 
 #include "fcron.h"
 
@@ -33,7 +33,7 @@
 #include "socket.h"
 #endif
 
-char rcs_info[] = "$Id: fcron.c,v 1.63 2002-03-31 17:20:35 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.64 2002-07-19 19:36:10 thib Exp $";
 
 void main_loop(void);
 void check_signal(void);
@@ -508,13 +508,15 @@ main(int argc, char **argv)
        die_e("Could not change dir to %s", fcrontabs);
     
 
+    freopen("/dev/null", "r", stdin);
+
     if (foreground == 0) {
 
-       /* close stdin, stdout and stderr.
+       /* close stdout and stderr.
         * close unused descriptors
         * optional detach from controlling terminal */
 
-       int fd, i;
+       int fd;
        pid_t pid;
 
        switch ( pid = fork() ) {
@@ -537,12 +539,9 @@ main(int argc, char **argv)
            ioctl(fd, TIOCNOTTY, 0);
            close(fd);
        }
-
-       if ( (i = open("/dev/null", O_RDWR)) < 0)
-           die_e("open: /dev/null:");
-       close(0); dup2(i, 0);
-       close(1); dup2(i, 1);
-       close(2); dup2(i, 2);
+       
+       freopen("/dev/null", "w", stdout);
+       freopen("/dev/null", "w", stderr);
 
        /* close most other open fds */
        xcloselog();
diff --git a/job.h b/job.h
index eafc4678213dc35e7e6dae4bdea02e4529138c0d..cd93f9598d748811cb4b0f2c18558272b12d2aeb 100644 (file)
--- a/job.h
+++ b/job.h
@@ -21,7 +21,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: job.h,v 1.4 2001-12-23 22:03:55 thib Exp $ */
+ /* $Id: job.h,v 1.5 2002-07-19 19:32:28 thib Exp $ */
 
 #ifndef __JOB_H__
 #define __JOB_H__
@@ -29,8 +29,7 @@
 /* functions prototypes */
 extern int change_user(struct CL *cl);
 extern void run_job(struct exe *exeent);
-extern int create_mail(struct CL *line, char *subject);
-extern void launch_mailer(struct CL *line, int mailfd);
-extern void xwrite(int fd, char *string);
+extern FILE *create_mail(struct CL *line, char *subject);
+extern void launch_mailer(struct CL *line, FILE *mailf);
 
 #endif /* __JOB_H__ */