aboutsummaryrefslogtreecommitdiffstats
path: root/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'env.c')
-rw-r--r--env.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/env.c b/env.c
index 06cfcb38..d181945a 100644
--- a/env.c
+++ b/env.c
@@ -110,15 +110,43 @@ void envquery(int argc, char **argv)
endpwent();
+ /* This documentation added to 6.4.1,
+ * and manual page corrected.
+ *
+ * here's the home directory logic:
+ * 1. we derive home. it is taken from:
+ * a. HOME_ETC
+ * b. HOME
+ * c. the user's passwd entry
+ * 2. we derive fmhome. It is normally
+ * a. home.
+ * b. It can be overridden from FETCHMAILHOME.
+ * If and only if fmhome != home, then the
+ * default configuration files will be expected
+ * without leading dots.
+ */
+
/* compute user's home directory */
home = getenv("HOME_ETC");
- if (!home && !(home = getenv("HOME")))
+ if (!home)
+ home = getenv("HOME");
+ if (!home)
home = xstrdup(pwp->pw_dir);
+ /* and make it an absolute path, so we
+ * can optionally chdir("/") later in daemonize()
+ * without changing behaviour.
+ */
+ {
+ static char _home_abs[_POSIX_PATH_MAX];
+ char *tmp = realpath(home, _home_abs);
+ if (tmp) home = _home_abs;
+ }
/* compute fetchmail's home directory */
fmhome = getenv("FETCHMAILHOME");
if (NULL == fmhome) {
fmhome = home;
+ at_home = 1;
}
/* and make it an absolute path, so we
* can optionally chdir("/") later in daemonize()
@@ -138,7 +166,7 @@ void envquery(int argc, char **argv)
* for its files. We don't want to do that if fetchmail has its
* own home ($FETCHMAILHOME), however.
*/
- rcfile = (char *)xmalloc(strlen(fmhome)+sizeof(RCFILE_NAME)+(fmhome==home)+2);
+ rcfile = (char *)xmalloc(strlen(fmhome) + sizeof(RCFILE_NAME) + 3);
/* avoid //.fetchmailrc */
if (strcmp(fmhome, "/") != 0)
strcpy(rcfile, fmhome);
@@ -147,7 +175,7 @@ void envquery(int argc, char **argv)
if (rcfile[strlen(rcfile) - 1] != '/')
strcat(rcfile, "/");
- if (fmhome==home)
+ if (at_home)
strcat(rcfile, ".");
strcat(rcfile, RCFILE_NAME);
}