Close logfile after a while waiting for non-smtp input. Bug 1891
authorJeremy Harris <jgh146exb@wizmail.org>
Sun, 2 Oct 2016 18:58:19 +0000 (19:58 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sun, 2 Oct 2016 18:58:19 +0000 (19:58 +0100)
src/src/exim.c
src/src/functions.h
src/src/log.c

index acc2af715fc23b2b5eda151489856619dfe28276..f05ba78a8b17a1d6ef99f81d4be668cdb3ef4678 100644 (file)
@@ -5531,7 +5531,7 @@ while (more)
     ignored; rejecting here would just add complication, and it can just as
     well be done later. Allow $recipients to be visible in the ACL. */
 
     ignored; rejecting here would just add complication, and it can just as
     well be done later. Allow $recipients to be visible in the ACL. */
 
-    if (acl_not_smtp_start != NULL)
+    if (acl_not_smtp_start)
       {
       uschar *user_msg, *log_msg;
       enable_dollar_recipients = TRUE;
       {
       uschar *user_msg, *log_msg;
       enable_dollar_recipients = TRUE;
@@ -5540,6 +5540,20 @@ while (more)
       enable_dollar_recipients = FALSE;
       }
 
       enable_dollar_recipients = FALSE;
       }
 
+    /* Pause for a while waiting for input.  If none received in that time,
+    close the logfile, if we had one open; then if we wait for a long-running
+    datasource (months, in one use-case) log rotation will not leave us holding
+    the file copy. */
+
+    if (!receive_timeout)
+      {
+      struct timeval t = { 30*60, 0 }; /* 30 minutess */
+      fd_set r;
+
+      FD_ZERO(&r); FD_SET(0, &r);
+      if (select(1, &r, NULL, NULL, &t) == 0) mainlog_close();
+      }
+
     /* Read the data for the message. If filter_test is not FTEST_NONE, this
     will just read the headers for the message, and not write anything onto the
     spool. */
     /* Read the data for the message. If filter_test is not FTEST_NONE, this
     will just read the headers for the message, and not write anything onto the
     spool. */
index b31a89fbc92f8a006a957f3356d8067aa2bfce1b..fd1e11d1ba5a7a3517666ee34e03c83d418693ad 100644 (file)
@@ -246,6 +246,7 @@ extern int     log_create_as_exim(uschar *);
 extern void    log_close_all(void);
 
 extern macro_item * macro_create(const uschar *, const uschar *, BOOL);
 extern void    log_close_all(void);
 
 extern macro_item * macro_create(const uschar *, const uschar *, BOOL);
+extern void    mainlog_close(void);
 #ifdef WITH_CONTENT_SCAN
 extern int     malware(const uschar *, int);
 extern int     malware_in_file(uschar *);
 #ifdef WITH_CONTENT_SCAN
 extern int     malware(const uschar *, int);
 extern int     malware_in_file(uschar *);
index fbf1042e751f54143962b8259812625db8ea4c50..6eb57ca750fe8bc6c7ea860ce2ea537b67009375 100644 (file)
@@ -663,6 +663,14 @@ while ((t = string_nextinlist(&tt, &sep, log_buffer, LOG_BUFFER_SIZE)))
 }
 
 
 }
 
 
+void
+mainlog_close(void)
+{
+if (mainlogfd < 0) return;
+(void)close(mainlogfd);
+mainlogfd = -1;
+mainlog_inode = 0;
+}
 
 /*************************************************
 *            Write message to log file           *
 
 /*************************************************
 *            Write message to log file           *
@@ -1004,14 +1012,8 @@ if (  flags & LOG_MAIN
     happening. */
 
     if (mainlogfd >= 0)
     happening. */
 
     if (mainlogfd >= 0)
-      {
       if (Ustat(mainlog_name, &statbuf) < 0 || statbuf.st_ino != mainlog_inode)
       if (Ustat(mainlog_name, &statbuf) < 0 || statbuf.st_ino != mainlog_inode)
-        {
-        (void)close(mainlogfd);
-        mainlogfd = -1;
-        mainlog_inode = 0;
-        }
-      }
+       mainlog_close();
 
     /* If the log is closed, open it. Then write the line. */
 
 
     /* If the log is closed, open it. Then write the line. */