aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2011-03-10 12:58:44 -0800
committerBrian Behlendorf <[email protected]>2011-03-10 12:58:44 -0800
commita6cba65ccae5a5458f9ab4ac11020716d30ea7f7 (patch)
treed7845e12daba3f52bbdec8e3cffdbf1d44a880c8
parent3eae80100bb32140aaa76864af636ea165584446 (diff)
Check for trailing '/' in mount.zfs
When run with a root '/' cwd the mount.zfs helper would strip not only the '/' but also the next character from the dataset name. For example, '/tank' was changed to 'ank' instead of just 'tank'. Originally, this was done for the '/tmp' cwd case where we needed to strip the '/' following the cwd. For example '/tmp/tank' needed to remove the '/tmp' cwd plus 1 character for the '/'. This change fixes the problem by checking the cwd and if it ends in a '/' it does not strip and extra character. Otherwise it will strip the next character. I believe this should only ever be true for the root directory. Closes #148
-rw-r--r--cmd/mount_zfs/mount_zfs.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c
index 32f092199..fbb954acd 100644
--- a/cmd/mount_zfs/mount_zfs.c
+++ b/cmd/mount_zfs/mount_zfs.c
@@ -218,10 +218,14 @@ static char *
parse_dataset(char *dataset)
{
char cwd[PATH_MAX];
+ int len;
(void) getcwd(cwd, PATH_MAX);
- if (!strncmp(cwd, dataset, strlen(cwd)))
- return (dataset + strlen(cwd) + 1);
+ len = strlen(cwd);
+
+ /* Do not add one when cwd already ends in a trailing '/' */
+ if (!strncmp(cwd, dataset, len))
+ return (dataset + len + (cwd[len-1] != '/'));
return (dataset);
}