Whamcloud - gitweb
LU-8257 utils: fix mtab symlink logic 60/21260/4
authorBob Glossman <bob.glossman@intel.com>
Tue, 12 Jul 2016 18:19:39 +0000 (11:19 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 6 Aug 2016 06:24:58 +0000 (06:24 +0000)
Existing logic to check if /etc/mtab is symlinked to /proc
fails if the symlink is ../proc/self/mounts.  This is in fact
the case in many newer linux distros, for example recent Fedora
versions.

This mod updates the logic in mtab_is_proc() to give the correct
answer for any symlink into /proc.
It also cleans up the exact text on some error messages.

Signed-off-by: Bob Glossman <bob.glossman@intel.com>
Change-Id: I49989f580c32e6baf820b88f6f9e6432aeded43d
Reviewed-on: http://review.whamcloud.com/21260
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/mount_utils.c

index cf4dca3..3de6f2a 100644 (file)
@@ -235,18 +235,16 @@ int check_mtab_entry(char *spec1, char *spec2, char *mtpt, char *type)
        return 0;
 }
 
-#define PROC_DIR       "/proc/"
+#include <sys/vfs.h>
+#include <linux/magic.h>
+
 static int mtab_is_proc(const char *mtab)
 {
-       char path[16];
-
-       if (readlink(mtab, path, sizeof(path)) < 0)
+       struct statfs s;
+       if (statfs(mtab, &s) < 0)
                return 0;
 
-       if (strncmp(path, PROC_DIR, strlen(PROC_DIR)))
-               return 0;
-
-       return 1;
+       return (s.f_type == PROC_SUPER_MAGIC);
 }
 
 #ifdef HAVE_LIBMOUNT
@@ -315,12 +313,12 @@ int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
 
        fp = setmntent(MOUNTED, "a+");
        if (fp == NULL) {
-               fprintf(stderr, "%s: setmntent(%s): %s:",
+               fprintf(stderr, "%s: setmntent(%s): %s\n",
                        progname, MOUNTED, strerror (errno));
                rc = 16;
        } else {
                if ((addmntent(fp, &mnt)) == 1) {
-                       fprintf(stderr, "%s: addmntent: %s:",
+                       fprintf(stderr, "%s: addmntent: %s\n",
                                progname, strerror (errno));
                        rc = 16;
                }