aboutsummaryrefslogtreecommitdiffstats
path: root/fetchmail.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2000-12-21 20:38:03 +0000
committerEric S. Raymond <esr@thyrsus.com>2000-12-21 20:38:03 +0000
commit50b850682e11c0e9f154d3dbdcb3497e96cabc76 (patch)
tree1b46973ea05b7e1927c7b552743e3f829c9e12b8 /fetchmail.c
parent15b6e12808c508e5a85031454f8149407729dfdf (diff)
downloadfetchmail-50b850682e11c0e9f154d3dbdcb3497e96cabc76.tar.gz
fetchmail-50b850682e11c0e9f154d3dbdcb3497e96cabc76.tar.bz2
fetchmail-50b850682e11c0e9f154d3dbdcb3497e96cabc76.zip
Dave Bodenstab's lockfile-acquisition change, and explanation.
svn path=/trunk/; revision=3001
Diffstat (limited to 'fetchmail.c')
-rw-r--r--fetchmail.c61
1 files changed, 43 insertions, 18 deletions
diff --git a/fetchmail.c b/fetchmail.c
index 918ef93c..ef349875 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -574,22 +574,25 @@ int main(int argc, char **argv)
#ifndef O_SYNC
#define O_SYNC 0 /* use it if we have it */
#endif
- if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
+ if (!lock_acquired)
{
- sprintf(tmpbuf,"%d", getpid());
- write(st, tmpbuf, strlen(tmpbuf));
- if (run.poll_interval)
- {
- sprintf(tmpbuf," %d", run.poll_interval);
- write(st, tmpbuf, strlen(tmpbuf));
- }
- close(st); /* should be safe, fd was opened with O_SYNC */
- lock_acquired = TRUE;
- }
- else
- {
- fprintf(stderr, _("fetchmail: lock creation failed.\n"));
- return(PS_EXCLUDE);
+ if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
+ {
+ sprintf(tmpbuf,"%d", getpid());
+ write(st, tmpbuf, strlen(tmpbuf));
+ if (run.poll_interval)
+ {
+ sprintf(tmpbuf," %d", run.poll_interval);
+ write(st, tmpbuf, strlen(tmpbuf));
+ }
+ close(st); /* should be safe, fd was opened with O_SYNC */
+ lock_acquired = TRUE;
+ }
+ else
+ {
+ fprintf(stderr, _("fetchmail: lock creation failed.\n"));
+ return(PS_EXCLUDE);
+ }
}
/*
@@ -616,7 +619,30 @@ int main(int argc, char **argv)
else if (rcstat.st_mtime > parsetime)
{
report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
- execvp("fetchmail", argv);
+ /*
+ * Matthias Andree: Isn't this prone to introduction of
+ * "false" programs by interfering with PATH? Those
+ * path-searching execs might not be the best ideas for
+ * this reason.
+ *
+ * Rob Funk: But is there any way for someone to modify
+ * the PATH variable of a running fetchmail? I don't know
+ * of a way.
+ *
+ * Dave's change makes fetchmail restart itself in exactly
+ * the way it was started from the shell (or shell script)
+ * in the first place. If you're concerned about PATH
+ * contamination, call fetchmail initially with a full
+ * path, and use Dave's patch.
+ *
+ * Not using a -p variant of exec means that the restart
+ * will break if both (a) the user depended on PATH to
+ * call fetchmail in the first place, and (b) the system
+ * doesn't save the whole path in argv[0] if the whole
+ * path wasn't used in the initial call. (If I recall
+ * correctly, Linux saves it but many other Unices don't.)
+ */
+ execvp(argv[0], argv);
report(stderr, _("attempt to re-exec fetchmail failed\n"));
}
@@ -629,8 +655,7 @@ int main(int argc, char **argv)
* filters out DNS queries over TCP/IP for reasons having to do
* with some obscure kernel problem involving bootstrapping of
* dynamically-addressed links. I don't understand this mess
- * and don't want to, so it's "See ya!" to this hack.
- */
+ * and don't want to, so it's "See ya!" to this hack. */
sethostent(TRUE); /* use TCP/IP for mailserver queries */
#endif /* HAVE_RES_SEARCH */