auth: avoid excessive stat of cellservdb
[openafs.git] / src / auth / cellconfig.c
index 896c5e7..a230cbb 100644 (file)
@@ -12,6 +12,7 @@
 #include <afs/stds.h>
 
 #include <roken.h>
+#include <afs/opr.h>
 
 #ifdef AFS_NT40_ENV
 #include <sys/utime.h>
@@ -350,6 +351,12 @@ _afsconf_UpToDate(struct afsconf_dir *adir)
     char *cellservDB;
     struct stat tstat;
     int code;
+    time_t now = time(0);
+
+    if (adir->timeCheck == now) {
+       return 1; /* stat no more than once a second */
+    }
+    adir->timeCheck = now;
 
     _afsconf_CellServDBPath(adir, &cellservDB);
     if (cellservDB == NULL)
@@ -402,6 +409,7 @@ _afsconf_Touch(struct afsconf_dir *adir)
 #endif
 
     adir->timeRead = 0;                /* just in case */
+    adir->timeCheck = 0;
 
     _afsconf_CellServDBPath(adir, &cellservDB);
     if (cellservDB == NULL)
@@ -658,6 +666,9 @@ afsconf_OpenInternal(struct afsconf_dir *adir, char *cell,
        return -1;
     }
 
+    /* init the keys queue before any call to afsconf_CloseInternal() */
+    _afsconf_InitKeys(adir);
+
     /* The CellServDB file is now open.
      * The following code parses the contents of the
      * file and creates a list with the first cell entry
@@ -809,9 +820,8 @@ afsconf_OpenInternal(struct afsconf_dir *adir, char *cell,
 
     if (tf != NULL)
        fclose(tf);
-    /* now read the fs keys, if possible */
 
-    _afsconf_InitKeys(adir);
+    /* now read the fs keys, if possible */
     code = _afsconf_LoadKeys(adir);
 
     return code;