]> diplodocus.org Git - nmh/blobdiff - sbr/context_read.c
Set MH_VERSION, OAUTH_SUPPORT, and CURL_USER_AGENT in tests/common.sh.in
[nmh] / sbr / context_read.c
index 3084ff531a19174573fd4f4476d68cff7041ce5d..803406881024fc8dfe8883911e50ae8d88f8931a 100644 (file)
@@ -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 <h/mh.h>                              /* mh internals */
-#include <errno.h>                             /* system call errors */
 #include <pwd.h>                               /* structure for getpwuid() results */
 
 void
@@ -37,6 +34,14 @@ context_read (void)
     struct     stat            st;             /* stat() results */
     register   struct  passwd  *pw;            /* getpwuid() results */
     register   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,
@@ -60,6 +65,8 @@ 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);
 
@@ -106,7 +113,7 @@ context_read (void)
        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)
@@ -120,11 +127,20 @@ context_read (void)
     if ((cp = getenv ("MHCONTEXT")) == (char *)0 || *cp == '\0')
        cp = context;
 
+    /* context is NULL if context_foil() was called to disable use of context
+     * We also support users setting explicitly setting MHCONTEXT to /dev/null.
+     * (if this wasn't specialcased then the locking would be liable to fail)
+     */
+    if (!cp || (strcmp(cp,"/dev/null") == 0)) {
+       ctxpath = NULL;
+       return;
+    }
+    
     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;