]> Pileus Git - ~andy/fetchmail/commitdiff
Merge logfile/syslog cleanup from legacy_63 branch.
authorMatthias Andree <matthias.andree@gmx.de>
Sun, 23 Sep 2012 12:58:06 +0000 (14:58 +0200)
committerMatthias Andree <matthias.andree@gmx.de>
Sun, 23 Sep 2012 12:58:06 +0000 (14:58 +0200)
NEWS
fetchmail.c
fetchmail.man

diff --git a/NEWS b/NEWS
index 23984363c10f5229f1e0a890a325ae6f09f997f7..6c05420cc2a8b05fdcfe5af2e9ea318deaeaf60f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -160,6 +160,8 @@ after 6.3.22 not available on their own in a newer 6.3.X release.
 # BUG FIXES
 * Fix combination of --plugin and -f -. Patch by Alexander Zangerl,
   to fix Debian Bug#671294.
+* Clean up logfile vs. syslog handling, and in case logfile overrides
+  syslog, send a message to the latter stating where logging goes.
 
 
 fetchmail-6.3.22 (released 2012-08-29, 26077 LoC):
index e30486f5f1c6cb62eecb5733379eed50aeae18bc..2498e471e1b40f7ae9bce91ff7c05d2307d0b46a 100644 (file)
@@ -574,19 +574,48 @@ int main(int argc, char **argv)
     if (!quitonly)
        implicitmode = load_params(argc, argv, optind);
 
-    /* precedence: logfile (if effective) overrides syslog. */
-    if (run.logfile && run.poll_interval && !nodetach) {
-       run.use_syslog = 0;
+    if (run.logfile) {
+       /* nodetach -> turn off logfile option */
+       if (nodetach) {
+           if (outlevel >= O_DEBUG) { fprintf(stderr, GT_("The nodetach option is in effect, ignoring logfile option.\n")); }
+           xfree(run.logfile);
+       }
+
+       /* not in daemon mode -> turn off logfile option */
+       if (0 == run.poll_interval) {
+           if (outlevel >= O_DEBUG) { fprintf(stderr, GT_("Not running in daemon mode, ignoring logfile option.\n")); }
+           xfree(run.logfile);
+       }
+
+       /* log file not writable -> turn off logfile option */
+       if (run.logfile && 0 != access(run.logfile, F_OK)) {
+           if (outlevel >= O_DEBUG) { fprintf(stderr, GT_("Logfile \"%s\" does not exist, ignoring logfile option.\n"), run.logfile); }
+           xfree(run.logfile);
+       }
+
+       /* log file not writable -> turn off logfile option */
+       if (run.logfile && 0 != access(run.logfile, W_OK)) {
+           if (outlevel >= O_DEBUG) { fprintf(stderr, GT_("Logfile \"%s\" is not writable, aborting.\n"), run.logfile); }
+           xfree(run.logfile);
+           exit(PS_UNDEFINED);
+       }
     }
 
     /* logging should be set up early in case we were restarted from exec */
     if (run.use_syslog)
     {
        openlog(program_name, LOG_PID, LOG_MAIL);
-       report_init(-1);
+       /* precedence: logfile (if effective) overrides syslog. */
+       if (run.logfile) {
+           syslog(LOG_ERR, GT_("syslog and logfile options are both set, ignoring syslog, and logging to %s"), run.logfile);
+           run.use_syslog = 0;
+           report_init((run.poll_interval == 0 || nodetach) && !run.logfile); /* when changing this, change copy below, too */
+       } else {
+           report_init(-1);
+       }
     }
     else
-       report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
+       report_init((run.poll_interval == 0 || nodetach) && !run.logfile); /* when changing this, change copy above, too */
 
 #ifdef POP3_ENABLE
     /* initialize UID handling */
@@ -865,14 +894,12 @@ int main(int argc, char **argv)
     else
     {
        /* not in daemon mode */
-       if (run.logfile && !nodetach && access(run.logfile, F_OK) == 0)
-       {
+       if (run.logfile)
+       {
            if (!freopen(run.logfile, "a", stdout))
                    report(stderr, GT_("could not open %s to append logs to\n"), run.logfile);
            if (!freopen(run.logfile, "a", stderr))
                    report(stdout, GT_("could not open %s to append logs to\n"), run.logfile);
-           if (run.use_syslog)
-               report(stdout, GT_("fetchmail: Warning: syslog and logfile are set. Check both for logs!\n"));
        }
     }
 
index 45f2cb98a25c15cd9e34061f10bd2ed6f5787e32..8f80db38f45c5bb897db1811a295cadc61733f67 100644 (file)
@@ -1336,6 +1336,8 @@ The
 option turns off use of
 .BR syslog (3),
 assuming it's turned on in the \fI~/.fetchmailrc\fP file.
+This option is overridden, in certain situations, by \fB\-\-logfile\fP (which
+see).
 .PP
 The
 .B \-N
@@ -1347,8 +1349,7 @@ fetchmail runs as the child of a supervisor process such as
 .BR init (8)
 or Gerrit Pape's
 .BR runit (8).
-Note that this also causes the logfile option to be ignored (though
-perhaps it shouldn't).
+Note that this also causes the logfile option to be ignored.
 .PP
 Note that while running in daemon mode polling a IMAP2bis server,
 transient errors (such as DNS failures or sendmail delivery refusals)
@@ -1667,13 +1668,16 @@ Keep permanently undeliverable mail as though a temporary error had
 occurred (default).
 T}
 set logfile    \-L     \&      T{
-Name of a file to append error and status messages to.
+Name of a file to append error and status messages to.  Only effective
+in daemon mode and if fetchmail detaches.  If effective, overrides \fBset
+syslog\fP.
 T}
 set idfile     \-i     \&      T{
 Name of the file to store UID lists in.
 T}
 set    syslog  \&      \&      T{
-Do error logging through syslog(3).
+Do error logging through syslog(3). May be overriden by \fBset
+logfile\fP.
 T}
 set no syslog          \&      \&      T{
 Turn off error logging through syslog(3). (default)
@@ -2188,7 +2192,8 @@ authentication.  These defaults may be overridden by later options.
 There are some global option statements: 'set logfile'
 followed by a string sets the same global specified by \-\-logfile.  A
 command-line \-\-logfile option will override this. Note that \-\-logfile is
-only effective if fetchmail detaches itself from the terminal and the
+only effective if fetchmail detaches itself from the terminal, is in
+daemon mode, and if the
 logfile already exists before fetchmail is run, and it overrides
 \-\-syslog in this case.  Also,
 \&'set daemon' sets the poll interval as \-\-daemon does.  This can be