X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=fetchmail.c;h=f7bcfd940e1abae19fbc45e9a262db6a3ea65f9e;hb=5b0e1fdef9c55b9c8a54f5c146fc84dab3b82e63;hp=6456ed284906c68952bc805fc2eff9a9b4f2fda5;hpb=7ee9e083f932920866a167846407e507ee558d97;p=~andy%2Ffetchmail diff --git a/fetchmail.c b/fetchmail.c index 6456ed28..f7bcfd94 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -137,8 +137,8 @@ static void printcopyright(FILE *fp) { fprintf(fp, GT_("Copyright (C) 2002, 2003 Eric S. Raymond\n" "Copyright (C) 2004 Matthias Andree, Eric S. Raymond,\n" " Robert M. Funk, Graham Wilson\n" - "Copyright (C) 2005 - 2006, 2010 - 2011 Sunil Shetye\n" - "Copyright (C) 2005 - 2011 Matthias Andree\n" + "Copyright (C) 2005 - 2006, 2010 - 2012 Sunil Shetye\n" + "Copyright (C) 2005 - 2012 Matthias Andree\n" )); fprintf(fp, GT_("Fetchmail comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n" "are welcome to redistribute it under certain conditions. For details,\n" @@ -307,9 +307,33 @@ 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_NORMAL) { fprintf(stderr, GT_("The nodetach option is in effect, ignoring logfile option.\n")); } + xfree(run.logfile); + } + +#if 0 + /* not in daemon mode -> turn off logfile option */ + if (0 == run.poll_interval) { + if (outlevel >= O_NORMAL) { fprintf(stderr, GT_("Not running in daemon mode, ignoring logfile option.\n")); } + xfree(run.logfile); + } +#endif + + /* log file not writable -> turn off logfile option */ + if (run.logfile && 0 != access(run.logfile, F_OK)) { + if (outlevel >= O_NORMAL) { 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)) { + fprintf(stderr, GT_("Logfile \"%s\" is not writable, aborting.\n"), run.logfile); + xfree(run.logfile); + exit(PS_UNDEFINED); + } } #if defined(HAVE_SYSLOG) @@ -322,11 +346,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 +632,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")); } }