X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/b9d1fc0c85e9bd18e5e768913ba2c0a00f19876c..30dd986c9c8d1a6fc75a7442c8ecf9eb16346f33:/sbr/context_read.c?ds=inline diff --git a/sbr/context_read.c b/sbr/context_read.c index 6a1eea12..748114ed 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -1,8 +1,6 @@ /* * context_read.c -- find and read profile and context files * - * $Id$ - * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. @@ -25,7 +23,6 @@ */ #include /* mh internals */ -#include /* system call errors */ #include /* structure for getpwuid() results */ void @@ -35,16 +32,24 @@ context_read (void) char *cp; /* miscellaneous pointer */ char *nd; /* nmh directory pointer */ struct stat st; /* stat() results */ - register struct passwd *pw; /* getpwuid() results */ - register FILE *ib; /* profile and context file pointer */ + struct passwd *pw; /* getpwuid() results */ + FILE *ib; /* profile and context file pointer */ + int failed_to_lock = 0; + + /* + * 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') + if ((mypath = getenv("HOME")) == NULL) { + if ((pw = getpwuid(getuid())) == NULL || *pw->pw_dir == '\0') adios(NULL, "cannot determine your home directory"); else mypath = pw->pw_dir; @@ -60,17 +65,19 @@ context_read (void) if ((cp = getenv("MH")) && *cp != '\0') { defpath = path(cp, TFILE); + /* defpath is an absolute path; make sure that always MH is, too. */ + setenv("MH", defpath, 1); 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); + adios(NULL, "`%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); + if ((ib = fopen(defpath, "r")) == NULL) + adios(NULL, "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."); + if ((ib = fopen(defpath, "r")) == NULL) + adios(NULL, "Doesn't look like nmh is installed. Run install-mh to do so."); cp = mh_profile; } @@ -83,7 +90,7 @@ context_read (void) * Convert a relative path name to an absolute one rooted in the home directory. */ - if ((cp = context_find ("path")) == (char *)0) + if ((cp = context_find ("path")) == NULL) adios(NULL, "Your %s file does not contain a path entry.", defpath); if (*cp == '\0') @@ -100,24 +107,24 @@ context_read (void) cp = concat ("Your MH-directory \"", nd, "\" doesn't exist; Create it? ", NULL); - if (!getanswer(cp)) + if (!read_yes_or_no_if_tty(cp)) adios (NULL, "unable to access MH-directory \"%s\"", nd); free (cp); if (!makedir (nd)) - adios (NULL, "unable to create", nd); + adios (NULL, "unable to create %s", nd); } else if ((st.st_mode & S_IFDIR) == 0) - adios ((char *)0, "`%s' is not a directory", nd); + adios (NULL, "`%s' is not a directory", nd); /* * Open and read user's context file. The name of the context file comes from the * profile unless overridden by the MHCONTEXT environment variable. */ - if ((cp = getenv ("MHCONTEXT")) == (char *)0 || *cp == '\0') + if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == '\0') cp = context; /* context is NULL if context_foil() was called to disable use of context @@ -131,9 +138,9 @@ context_read (void) ctxpath = getcpy (m_maildir (cp)); - if ((ib = lkfopen (ctxpath, "r"))) { + if ((ib = lkfopendata (ctxpath, "r", &failed_to_lock))) { readconfig ((struct node **) 0, ib, cp, 1); - lkfclose (ib, ctxpath); + lkfclosedata (ib, ctxpath); } return;