On Linux and IRIX, fail gracefully when we fail to open /etc/mtab,
instead of segfaulting. Move strdup'ing cacheMountDir until after
opening /etc/mtab, to simplify the error handling.
Change-Id: I58d64548303f25a51753d093a733608fea1282e1
Reviewed-on: http://gerrit.openafs.org/4825
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
#else
#if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
struct mntent tmntent;
- char *dir = strdup(cacheMountDir);
+ char *dir;
int i;
+ tfilep = setmntent("/etc/mtab", "a+");
+ if (!tfilep) {
+ printf("Can't open /etc/mtab for writing (errno %d); not adding "
+ "an entry for AFS\n", errno);
+ return 1;
+ }
+
+ dir = strdup(cacheMountDir);
+
/* trim trailing slashes; don't look at dir[0] in case we are somehow
* just "/" */
for (i = strlen(dir)-1; i > 0; i--) {
}
}
- tfilep = setmntent("/etc/mtab", "a+");
tmntent.mnt_fsname = "AFS";
tmntent.mnt_dir = dir;
tmntent.mnt_type = "afs";