From 325443e6178f9dcdba7326bdb675447ac72bd540 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 6 Apr 2011 16:56:22 -0500 Subject: [PATCH] afsd: Trim trailing slashes on Linux mntent When we write a mount entry on Linux when mounting /afs, trim trailing slashes on the mount path. Otherwise, the umount utility can get slightly confused, and leave the /afs mount entry in /etc/mtab after it's been unmounted. For full correctness we should probably completely canonicalize the path like the mount utility does, but it's unlikely that anyone will provide significantly weird paths for cacheMountDir, so don't bother. Change-Id: Ie8330f08918d52eee319dff5f6ad275c30164c67 Reviewed-on: http://gerrit.openafs.org/4442 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/afsd/afsd_kernel.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c index c0b9531fb..91f0d1b38 100644 --- a/src/afsd/afsd_kernel.c +++ b/src/afsd/afsd_kernel.c @@ -407,16 +407,31 @@ HandleMTab(char *cacheMountDir) #else #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV) struct mntent tmntent; + char *dir = strdup(cacheMountDir); + int i; + + /* trim trailing slashes; don't look at dir[0] in case we are somehow + * just "/" */ + for (i = strlen(dir)-1; i > 0; i--) { + if (dir[i] == '/') { + dir[i] = '\0'; + } else { + break; + } + } tfilep = setmntent("/etc/mtab", "a+"); tmntent.mnt_fsname = "AFS"; - tmntent.mnt_dir = cacheMountDir; + tmntent.mnt_dir = dir; tmntent.mnt_type = "afs"; tmntent.mnt_opts = "rw"; tmntent.mnt_freq = 1; tmntent.mnt_passno = 3; addmntent(tfilep, &tmntent); endmntent(tfilep); + + free(dir); + dir = NULL; #else struct mntent tmntent; -- 2.39.5