X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=fetchmail.c;h=d720b04539172120dc902918a801dde91143f249;hb=33cddbff323efcbae1503e91e6e65b2733da80c7;hp=e30486f5f1c6cb62eecb5733379eed50aeae18bc;hpb=b5a52578dc64a15121c49c72f1441e15603edcf4;p=~andy%2Ffetchmail diff --git a/fetchmail.c b/fetchmail.c index e30486f5..d720b045 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -133,7 +133,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 - 2012 Matthias Andree, Sunil Shetye\n" + "Copyright (C) 2005 - 2012 Sunil Shetye\n" + "Copyright (C) 2005 - 2013 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" @@ -421,7 +422,6 @@ static int get_pwmd_details(const char *pwmd_account, int protocol, return 0; } #endif - int main(int argc, char **argv) { int bkgd = FALSE; @@ -471,7 +471,6 @@ int main(int argc, char **argv) #define IDFILE_NAME ".fetchids" run.idfile = prependdir (IDFILE_NAME, fmhome); - outlevel = O_NORMAL; /* @@ -574,19 +573,50 @@ 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); + } } /* 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 +895,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")); } } @@ -1109,7 +1137,6 @@ int main(int argc, char **argv) pwm = NULL; } #endif - /* close connections cleanly */ terminate_poll(0); @@ -1405,7 +1432,6 @@ static int load_params(int argc, char **argv, int optind) fprintf(stderr,GT_("Warning: multiple mentions of host %s in config file\n"),argv[optind]); ctl->active = TRUE; predeclared = TRUE; - #ifdef HAVE_LIBPWMD if (ctl->pwmd_file) { /* @@ -1436,7 +1462,6 @@ static int load_params(int argc, char **argv, int optind) * call later on. */ ctl = hostalloc((struct query *)NULL); - #ifdef HAVE_LIBPWMD if (cmd_opts.pwmd_file) { /* @@ -1644,6 +1669,7 @@ static int load_params(int argc, char **argv, int optind) if (!ctl->localnames) /* for local delivery via SMTP */ save_str_pair(&ctl->localnames, user, NULL); + /* * can't handle multidrop mailboxes without "envelope" * option, this causes truckloads full of support complaints @@ -1761,6 +1787,7 @@ static void terminate_run(int sig) if (ctl->password) memset(ctl->password, '\0', strlen(ctl->password)); + if (activecount == 0) exit(PS_NOMAIL); else @@ -1877,7 +1904,6 @@ static int print_id_of(struct uid_db_record *rec, void *unused) printf("\t%s\n", rec->id); return 0; } - static void dump_params (struct runctl *runp, struct query *querylist, flag implicit) /* display query parameters in English */ @@ -2275,6 +2301,7 @@ static void dump_params (struct runctl *runp, printf(GT_(" No UIDs saved from this host.\n")); else { + printf(GT_(" %d UIDs saved.\n"), count); traverse_uid_db(&ctl->oldsaved, print_id_of, NULL); }