summaryrefslogtreecommitdiffstats
path: root/usr.sbin/snapinfo
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2007-03-16 12:36:54 +0000
committerpjd <pjd@FreeBSD.org>2007-03-16 12:36:54 +0000
commit57ed96b72c052f2a2c3eefc5773c07b51df7a4f1 (patch)
treef4d821fa2af47544a5fbc6cf630ee91d93206b8b /usr.sbin/snapinfo
parentc93bd7d0c41d724f25881bf2da44b9707ceabd9f (diff)
downloadFreeBSD-src-57ed96b72c052f2a2c3eefc5773c07b51df7a4f1.zip
FreeBSD-src-57ed96b72c052f2a2c3eefc5773c07b51df7a4f1.tar.gz
Imagine a situation where:
# ls -ld /mnt/{foo,bar} drwxr-xr-x 3 root wheel 512 Mar 16 06:56 /mnt/bar lrwxr-xr-x 1 root wheel 3 Mar 16 12:10 /mnt/foo -> bar # grep /mnt/foo /etc/fstab /dev/da1 /mnt/foo ufs rw 0 0 Which means, we give symbolic link as a mount point to mount(8), but mount(8) use realpath(3) before mounting the file systems, so we get: # mount | grep /dev/da1 /dev/da1 on /mnt/bar (ufs, local) Before the commit: # snapinfo /mnt/foo usage: snapinfo [-v] -a snapinfo [-v] mountpoint # snapinfo /mnt/bar /mnt/bar/snap This commit makes snapinfo(8) to first realpath(3) the given mount point and now we have: # snapinfo /mnt/foo /mnt/bar/snap # snapinfo /mnt/bar /mnt/bar/snap
Diffstat (limited to 'usr.sbin/snapinfo')
-rw-r--r--usr.sbin/snapinfo/snapinfo.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/usr.sbin/snapinfo/snapinfo.c b/usr.sbin/snapinfo/snapinfo.c
index a4b1a13..55b54a5 100644
--- a/usr.sbin/snapinfo/snapinfo.c
+++ b/usr.sbin/snapinfo/snapinfo.c
@@ -81,12 +81,19 @@ main(int argc, char **argv)
usage();
if (!all) {
- path = *argv;
+ char resolved[PATH_MAX];
- if (strrchr(path, '/') == NULL || /* is absolute path */
- (stat(path, &st) == -1) || /* is it stat'able */
- !(st.st_mode & S_IFDIR)) /* is it a directory */
+ path = *argv;
+ /*
+ * mount(8) use realpath(3) before mounting file system,
+ * so let's do the same with the given path.
+ */
+ if (realpath(path, resolved) == NULL || /* can create full path */
+ stat(resolved, &st) == -1 || /* is it stat'able */
+ !S_ISDIR(st.st_mode)) { /* is it a directory */
usage();
+ }
+ path = resolved;
}
fscount = getmntinfo(&mntbuf, MNT_WAIT);
OpenPOWER on IntegriCloud