afsd: Trim trailing slashes on Linux mntent
authorAndrew Deason <adeason@sinenomine.net>
Wed, 6 Apr 2011 21:56:22 +0000 (16:56 -0500)
committerDerrick Brashear <shadow@dementia.org>
Fri, 8 Apr 2011 13:09:54 +0000 (06:09 -0700)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/afsd/afsd_kernel.c

index c0b9531..91f0d1b 100644 (file)
@@ -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;