Hi friends,
here is a patch from a Debian user that fixes a very annoying behavior
of fetchmail as a daemon. Modifying the rc file could lead fetchmail
to loop infinitely.
Cheers,
Benjamin
--- Begin Message ---
Package: fetchmail
Version: 6.2.4-3
Severity: normal
Tags: patch
Followup-For: Bug #202787
I have experienced this bug as well. I've attached a patch for the deb sources
that corrects the problem.
To reproduce the bug (at least for me):
Make sure that fetchmail is configured to run in daemon mode. Execute:
# /etc/init.d/fetchmail debug-run
When the daemon goes to sleep, execute (from another shell):
# touch /etc/fetchmailrc
# /etc/init.d/fetchmail awaken
(the awaken command isn't necessary to cause the error, but otherwise
you'll have to wait for the daemon to awaken itself)
As soon as the daemon awakens, it will notice that it's config file has
been updated and will perform a self-restart.
It will then continually self-restart in an infinte loop until it is killed.
I found the cause to be the following:
When fetchmail is initializing, it checks to see if there is another copy of
itself running in the background already, in which case it doesn't read it's
config file since (presumably) the only reason the new copy of fetchmail was
started was to perform some action upon the already running copy (for instance,
to kill it). It does the check for an existing daemon by looking in the pid
lockfile. If it finds an existing process, it doesn't re-read the config.
While fetchmail is already running and it detects a change in the config file,
it will restart the process (so that it can re-read it's config). It doesn't
remove it's own pid file before it restarts.
Upon restart (because the pid file was not removed) fetchmail thinks that there
is a process already running and doesn't read the config file.
Finally, since the config file was not read, it doesn't know anything about it,
and so it appears to the daemon that the config file on disk is *more recent*
than the one it last read. This causes the daemon to perform another
"self-restart" which throws it into the infinite loop.
The patch:
The patch below alters fetchmail's behavior during startup so that it checks to
see if the pid in the lockfile is it's own pid, which should indicate that it
just performed a self-restart (since it inherits the old pid, and doesn't
remove the lockfile). If this is the case, it loads the config file anyways to
make sure that the it "knows" about the config file's real modification time,
making sure that the daemon doesn't "self-restart" until the next time the
config file is actually changed.
diff -Nuprd fetchmail-6.2.4/fetchmail.c
fetchmail-6.2.4-fix_config_reload/fetchmail.c
--- fetchmail-6.2.4/fetchmail.c 2003-10-28 23:38:06.000000000 -0500
+++ fetchmail-6.2.4-fix_config_reload/fetchmail.c 2003-10-28
23:43:41.000000000 -0500
@@ -255,8 +255,13 @@ int main(int argc, char **argv)
bkgd = (pid < 0);
pid = bkgd ? -pid : pid;
- /* avoid parsing the config file if all we're doing is killing a daemon */
- if (!quitmode && !pid)
+ /*
+ * Avoid parsing the config file if all we're doing is killing a daemon,
+ * unless this appears to be a self-restarted instance because we detected
an
+ * "under-our-noses" configuration file change, in which case we
definitely want
+ * to reload the config file.
+ */
+ if ( ( !quitmode && !pid ) || pid == getpid() )
implicitmode = load_params(argc, argv, optind);
else if (pid)
implicitmode = 1;
-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux thinkpad 2.4.22+netcarbon.thinkpad.t30+0.0.6+2003.09.30.16.00 #1
Tue Sep 30 16:47:34 EDT 2003 i686
Locale: LANG=C, LC_CTYPE=C
Versions of packages fetchmail depends on:
ii adduser 3.51 Add and remove users and groups
ii base-files 3.0.11 Debian base system miscellaneous f
ii debconf 1.3.17 Debian configuration management sy
ii debianutils 2.5.5 Miscellaneous utilities specific t
ii libc6 2.3.2-8 GNU C Library: Shared libraries an
ii libssl0.9.7 0.9.7c-5 SSL shared libraries
-- debconf information:
* fetchmail/initdefaultswarn:
* fetchmail/runasroot: false
* fetchmail/confwarn:
fetchmail/fetchidswarn:
* fetchmail/systemwide: true
fetchmail-6.2.4-fix_config_reload.patch
Description: Text Data
pgpR2VcHGnQ8L.pgp
Description: PGP signature
--- End Message ---
--
.''`.
; ;' ; Debian GNU/Linux | Benjamin Drieu
`. `' http://www.debian.org/ | <benj(_at_)debian(_dot_)org>
`-