From 01bbe2820af01501a841eecebe15d31bc8f742e9 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 7 Jun 2014 19:21:16 +0200 Subject: [PATCH] mount: resolve path given this allows: cd /mnt; mount somename. --- mount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mount.c b/mount.c index 5e0bcff..071d59f 100644 --- a/mount.c +++ b/mount.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "util.h" struct { @@ -121,7 +122,7 @@ main(int argc, char *argv[]) { int aflag = 0, oflag = 0, status = EXIT_SUCCESS, i; unsigned long flags = 0; - char *types = NULL, data[512] = ""; + char *types = NULL, data[512] = "", *resolvpath = NULL; char *files[] = { "/proc/mounts", "/etc/fstab", NULL }; size_t datasiz = sizeof(data); const char *source, *target; @@ -177,6 +178,9 @@ main(int argc, char *argv[]) source = NULL; if(stat(target, &st) < 0) eprintf("stat %s:", target); + if(!(resolvpath = realpath(target, NULL))) + eprintf("realpath %s:", target); + target = resolvpath; } for(i = 0; files[i]; i++) { @@ -214,6 +218,7 @@ mountsingle: } if(fp) endmntent(fp); + free(resolvpath); return status; mountall: