diff -Naur fetchmail-5.9.13.orig/fetchmail.c fetchmail-5.9.13/fetchmail.c --- fetchmail-5.9.13.orig/fetchmail.c Sun Jun 23 01:33:11 2002 +++ fetchmail-5.9.13/fetchmail.c Mon Jul 1 14:06:00 2002 @@ -75,6 +75,11 @@ static struct runctl cmd_run; /* global options set from command line */ static time_t parsetime; /* time of last parse */ +/* this should be of size PATH_MAX */ +static char currentwd[1024] = ""; +static char *prependcwd (char *); +static int atleastonerelative = 0; + static void terminate_run(int); static void terminate_poll(int); @@ -117,6 +122,21 @@ #define timestamp rfc822timestamp #endif +static char *prependcwd (char *file) { + char *newfile; + if (!file || !file[0] || /* null path */ + file[0] == '/') /* absolute path */ + return file; + atleastonerelative++; + if (!currentwd[0]) /* we don't HAVE_GETCWD */ + return file; + newfile = xmalloc (strlen (currentwd) + 1 + strlen (file) + 1); + sprintf (newfile, "%s/%s", currentwd, file); + free (file); /* this should not be used now */ + return newfile; +} +#define PREPENDCWD(file) file = prependcwd (file) + int main(int argc, char **argv) { int bkgd = FALSE; @@ -478,6 +498,23 @@ */ if (run.poll_interval) { +#ifdef HAVE_GETCWD + /* save the current directory */ + if (getcwd (currentwd, sizeof (currentwd)) == NULL) { + report(stderr, GT_("could not get current working directory\n")); + currentwd[0] = 0; + } +#endif + PREPENDCWD (rcfile); + PREPENDCWD (run.idfile); + PREPENDCWD (run.logfile); + for (ctl = querylist; ctl; ctl = ctl->next) + { + PREPENDCWD (ctl->bsmtp); + PREPENDCWD (ctl->sslcert); + PREPENDCWD (ctl->sslkey); + } + if (!nodetach) daemonize(run.logfile, terminate_run); report(stdout, GT_("starting fetchmail %s daemon \n"), VERSION); @@ -541,6 +578,14 @@ else if (rcstat.st_mtime > parsetime) { report(stdout, GT_("restarting fetchmail (%s changed)\n"), rcfile); + + /* restore the startup directory */ + if (!currentwd[0] || chdir (currentwd) == -1) + { + if (atleastonerelative) + report(stderr, GT_("attempt to re-exec may fail as directory has not been restored\n")); + } + /* * Matthias Andree: Isn't this prone to introduction of * "false" programs by interfering with PATH? Those