[hackers] [ubase] mount: resolve path given || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sat, 07 Jun 2014 20:16:47 +0200

commit 01bbe2820af01501a841eecebe15d31bc8f742e9
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat Jun 7 19:21:16 2014 +0200

    mount: resolve path given
    
    this allows: cd /mnt; mount somename.

diff --git a/mount.c b/mount.c
index 5e0bcff..071d59f 100644
--- a/mount.c
+++ b/mount.c
_AT_@ -7,6 +7,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <limits.h>
 #include "util.h"
 
 struct {
_AT_@ -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;
_AT_@ -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++) {
_AT_@ -214,6 +218,7 @@ mountsingle:
         }
         if(fp)
                 endmntent(fp);
+ free(resolvpath);
         return status;
 
 mountall:
Received on Sat Jun 07 2014 - 20:16:47 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 07 2014 - 20:24:08 CEST