int code;
time_t now = time(0);
- if (adir->timeCheck == now) {
+ if (adir->timeRead && (adir->timeCheck == now)) {
return 1; /* stat no more than once a second */
}
adir->timeCheck = now;
if (!(home_dir = getenv("HOME"))) {
/* Our last chance is the "/.AFSCONF" file */
fp = fopen("/.AFSCONF", "r");
- if (fp == 0) {
- free(tdir);
- UNLOCK_GLOBAL_MUTEX;
- return (struct afsconf_dir *)0;
- }
+ if (fp == 0)
+ goto fail;
+
fgets(afs_confdir, 128, fp);
fclose(fp);
} else {
- char pathname[256];
+ char *pathname = NULL;
+
+ asprintf(&pathname, "%s/%s", home_dir, ".AFSCONF");
+ if (pathname == NULL)
+ goto fail;
- sprintf(pathname, "%s/%s", home_dir, ".AFSCONF");
fp = fopen(pathname, "r");
+ free(pathname);
+
if (fp == 0) {
/* Our last chance is the "/.AFSCONF" file */
fp = fopen("/.AFSCONF", "r");
- if (fp == 0) {
- free(tdir);
- UNLOCK_GLOBAL_MUTEX;
- return (struct afsconf_dir *)0;
- }
+ if (fp == 0)
+ goto fail;
}
fgets(afs_confdir, 128, fp);
fclose(fp);
}
len = strlen(afs_confdir);
- if (len == 0) {
- free(tdir);
- UNLOCK_GLOBAL_MUTEX;
- return (struct afsconf_dir *)0;
- }
+ if (len == 0)
+ goto fail;
+
if (afs_confdir[len - 1] == '\n') {
afs_confdir[len - 1] = 0;
}
code = afsconf_OpenInternal(tdir, 0, 0);
if (code) {
free(tdir->name);
- free(tdir);
- UNLOCK_GLOBAL_MUTEX;
- return (struct afsconf_dir *)0;
+ goto fail;
}
}
UNLOCK_GLOBAL_MUTEX;
return tdir;
+
+fail:
+ free(tdir);
+ UNLOCK_GLOBAL_MUTEX;
+ return NULL;
}
static int
char *start, *p;
afsconf_FILE *fp;
- strcompose(tbuffer, 256, adir->name, "/", AFSDIR_THISCELL_FILE, NULL);
+ strcompose(tbuffer, 256, adir->name, "/", AFSDIR_THISCELL_FILE,
+ (char *)NULL);
fp = fopen(tbuffer, "r");
if (fp == 0) {
return -1;
cm_enumCellRegistry_t enumCellRegistry = {0, 0};
#endif /* AFS_NT40_ENV */
+ /* init the keys queue before any call to afsconf_CloseInternal() */
+ _afsconf_InitKeys(adir);
+
/* figure out the local cell name */
#ifdef AFS_NT40_ENV
i = GetCellNT(adir);
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
#endif /* AFS_NT40_ENV */
/* Read in the alias list */
- strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLALIAS_FILE, NULL);
+ strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLALIAS_FILE,
+ (char *)NULL);
tf = fopen(tbuffer, "r");
while (tf) {