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.8.0_pre1^2~3885 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=325443e6178f9dcdba7326bdb675447ac72bd540;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. Change-Id: Ie8330f08918d52eee319dff5f6ad275c30164c67 Reviewed-on: http://gerrit.openafs.org/4442 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- 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;