From: Andrew Deason Date: Wed, 6 Apr 2011 21:56:22 +0000 (-0500) Subject: afsd: Trim trailing slashes on Linux mntent X-Git-Tag: upstream/1.6.1.pre1^2~48 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=96ee498f82153285eb463623bb37ec7d625c10af;p=packages%2Fo%2Fopenafs.git 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. Reviewed-on: http://gerrit.openafs.org/4442 Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit 325443e6178f9dcdba7326bdb675447ac72bd540) Change-Id: I9832fad8a43278c5eb618e4148c71f8a9ef81e87 Reviewed-on: http://gerrit.openafs.org/6283 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear --- diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c index 750221216..d0c3a692e 100644 --- a/src/afsd/afsd_kernel.c +++ b/src/afsd/afsd_kernel.c @@ -405,16 +405,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;