From: Bob Glossman Date: Tue, 12 Jul 2016 18:19:39 +0000 (-0700) Subject: LU-8257 utils: fix mtab symlink logic X-Git-Tag: 2.8.56~5 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=1136148d2f07a282c45c45124039eca83a16f2cc;p=fs%2Flustre-release.git LU-8257 utils: fix mtab symlink logic 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 Change-Id: I49989f580c32e6baf820b88f6f9e6432aeded43d Reviewed-on: http://review.whamcloud.com/21260 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Nathaniel Clark Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index cf4dca3..3de6f2a 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -235,18 +235,16 @@ int check_mtab_entry(char *spec1, char *spec2, char *mtpt, char *type) return 0; } -#define PROC_DIR "/proc/" +#include +#include + 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; }