fetchmail-friends
[Top] [All Lists]

[fetchmail] directory change

2002-07-01 05:16:34
fetchmail sometimes fails in daemon mode when the rcfile is modified.
This can occur if some files mentioned in the rcfile are not absolute.

Case 1: If fetchmail is run with a relative rcfile on command line,
reexection never occurs!

$ pwd
/home/shetye
$ fetchmail -f .fetchmailrc -vv
$ touch .fetchmailrc
$ fetchmail
(does not reexecute)

Case 2: If the rcfile contains a relative logfile, say

set logfile "fetchmail.logs"

$ pwd
/home/shetye
$ fetchmail -vv
(opens "/home/shetye/fetchmail.logs")
$ touch .fetchmailrc
$ fetchmail
(tries to open "/fetchmail.logs")

Case 3: If the rcfile contains any relative file which is opened after
chdir(), it cannot not open it at all.

set idfile "testidfile"

$ pwd
/home/shetye
$ fetchmail -vv
(tries to open "/testidfile")

All this can be traced back to the innocuous looking chdir("/") in the
daemonize() function. There are several possible alternatives:

Solution 1: do not do any chdir() at all. After all, fetchmail does
have several files open, so umount() is anyway going to fail for some
partition or the other. Of course, it would seem harsh if some user
has invoked fetchmail from some nfs partition.

Solution 2: convert all filenames to absolute pathnames. Also, restore
the directory before reexecuting. This will require any new option in
the future with filenames to be converted to a full path.

Solution 3: do a chdir("/") only if there is no relative path
mentioned.

This has the same problem as patch 2. In addition, if a user mentions
a relative pathname later, it will not work. A typical case will be a
commented line like

#set logfile "fetchmail.logs"

which a user uncomments from time to time to see what is happening.

Solution 4: warn (and maybe quit) if any path is relative. Again, the
warning may not appear in the commented line case above.

Solution 5: do a chdir("~"). Most users anyway invoke fetchmail from
their home directory only. Document that all relative paths are
relative to home directory.

Solution 6: do a chdir() to the directory containing the rcfile
instead. This will keep all the files in the same directory. In the
default case, this will be the same as solution 5.

I have attached patches for solution 1 and 2.

Sunil Shetye.

Attachment: fetchmail-5.9.13-nochdir.patch
Description: Text document

Attachment: fetchmail-5.9.13-relative.patch
Description: Text document

<Prev in Thread] Current Thread [Next in Thread>