- /*
- * Find user's home directory
- */
- if (!mypath) {
- if ((mypath = getenv ("HOME")))
- mypath = getcpy (mypath);
- else
- if ((pw = getpwuid (getuid ())) == NULL
- || pw->pw_dir == NULL
- || *pw->pw_dir == 0)
- adios (NULL, "no HOME envariable");
- else
- mypath = getcpy (pw->pw_dir);
- if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
- *cp = 0;
- }
-
- /*
- * open and read user's profile
- */
- if ((cp = getenv ("MH")) && *cp != '\0') {
- defpath = path (cp, TFILE);
- if ((ib = fopen (defpath, "r")) == NULL)
- adios (defpath, "unable to read");
- if (*cp != '/')
- m_putenv ("MH", defpath);
- } else {
- defpath = concat (mypath, "/", mh_profile, NULL);
-
- if ((ib = fopen (defpath, "r")) == NULL) {
- switch (pid = vfork ()) {
- case -1:
- adios ("fork", "unable to");
-
- case 0:
- setgid (getgid ());
- setuid (getuid ());
-
- execlp (installproc, "install-mh", "-auto", NULL);
- fprintf (stderr, "unable to exec ");
- perror (installproc);
- _exit (-1);
-
- default:
- if (pidwait (pid, 0)
- || (ib = fopen (defpath, "r")) == NULL)
- adios (NULL, "[install-mh aborted]");
- }
+ /*
+ ** If this routine _is_ called again (despite the wanings in the
+ ** comments above), return immediately.
+ */
+ if ( m_defs != 0 )
+ return;
+
+ /*
+ ** Find user's home directory. Try the HOME environment variable first,
+ ** the home directory field in the password file if that's not found.
+ */
+ if ((mypath = getenv("HOME")) == (char *)0) {
+ if ((pw = getpwuid(getuid())) == (struct passwd *)0 ||
+ *pw->pw_dir == '\0')
+ adios(NULL, "cannot determine your home directory");
+ else
+ mypath = pw->pw_dir;
+ }
+
+ /*
+ ** Find and read user's profile. Check for the existence of
+ ** an MH environment variable first with non-empty contents.
+ ** Convert any relative path name found there to an absolute one.
+ ** Look for the profile in the user's home directory if the MH
+ ** environment variable isn't set.
+ */
+
+ if ((cp = getenv("MH")) && *cp != '\0') {
+ defpath = path(cp, TFILE);
+
+ if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0)
+ adios((char *)0, "`%s' specified by your MH environment variable is not a normal file", cp);
+
+ if ((ib = fopen(defpath, "r")) == (FILE *)0)
+ adios((char *)0, "unable to read the `%s' profile specified by your MH environment variable", defpath);
+ } else {
+ defpath = concat(mypath, "/", mh_profile, NULL);
+
+ if ((ib = fopen(defpath, "r")) == (FILE *)0)
+ adios((char *)0, "Doesn't look like nmh is installed. Run install-mh to do so.");
+
+ cp = mh_profile;