]> Pileus Git - ~andy/fetchmail/commitdiff
Clean up logfile vs. syslog handling.
authorMatthias Andree <matthias.andree@gmx.de>
Sun, 23 Sep 2012 12:44:25 +0000 (14:44 +0200)
committerMatthias Andree <matthias.andree@gmx.de>
Sun, 23 Sep 2012 12:44:25 +0000 (14:44 +0200)
In case logfile overrides syslog, send a message to the latter stating
where logging goes.  Also revise manual page.

NEWS
fetchmail.c
fetchmail.man

diff --git a/NEWS b/NEWS
index a0705cd8c223a9183a69889d87c4bb5b492ff8bf..2012440c75fdc988a54bd9e1c0c3a5ee115616cc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -72,6 +72,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 4327c6e4bce21c3da471e2a174a5195a1fe48d02..c02e4432d290275bae7b06d7b3b412ca104f91bd 100644 (file)
@@ -307,9 +307,31 @@ 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);
+       }
     }
 
 #if defined(HAVE_SYSLOG)
@@ -322,11 +344,18 @@ int main(int argc, char **argv)
        /* Assume BSD4.2 openlog with two arguments */
        openlog(program_name, LOG_PID);
 #endif
-       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
 #endif
-       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 */
@@ -601,14 +630,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 56026d0bea96acb40d896a9c351a9565036c215b..0a95f033abb28afbe06ea8204f37f5f8e00bd3c4 100644 (file)
@@ -1366,6 +1366,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
@@ -1377,8 +1379,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 POP2 or IMAP2bis server,
 transient errors (such as DNS failures or sendmail delivery refusals)
@@ -1702,13 +1703,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)
@@ -2226,7 +2230,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