dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
531551
From fbdd962ca187399cab3b0bf78d740e5fb304e0bf Mon Sep 17 00:00:00 2001
531551
From: Karel Zak <kzak@redhat.com>
531551
Date: Fri, 16 Dec 2016 12:19:32 +0100
531551
Subject: [PATCH] findmnt: fix --target behaviour
531551
531551
Upstream: https://github.com/karelzak/util-linux/commit/80c31a0b596125b387c6b27c899e8bad4e46680b
531551
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1405238
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 libmount/src/mountP.h |  1 +
531551
 libmount/src/tab.c    |  4 ++++
531551
 libmount/src/utils.c  |  9 +++++++++
531551
 misc-utils/findmnt.c  | 10 +++-------
531551
 4 files changed, 17 insertions(+), 7 deletions(-)
531551
531551
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
531551
index 7b0848f..6cabced 100644
531551
--- a/libmount/src/mountP.h
531551
+++ b/libmount/src/mountP.h
531551
@@ -164,6 +164,7 @@ extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
531551
 extern void mnt_free_filesystems(char **filesystems);
531551
 
531551
 extern char *mnt_get_kernel_cmdline_option(const char *name);
531551
+extern int mnt_stat_mountpoint(const char *target, struct stat *st);
531551
 
531551
 /* tab.c */
531551
 extern int mnt_table_set_parser_fltrcb(	struct libmnt_table *tb,
531551
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
531551
index 10ee7ce..5628da6 100644
531551
--- a/libmount/src/tab.c
531551
+++ b/libmount/src/tab.c
531551
@@ -528,6 +528,7 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
531551
 					    int direction)
531551
 {
531551
 	char *mnt;
531551
+	struct stat st;
531551
 
531551
 	if (!tb || !path || !*path)
531551
 		return NULL;
531551
@@ -536,6 +537,9 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
531551
 
531551
 	DBG(TAB, mnt_debug_h(tb, "lookup MOUNTPOINT: '%s'", path));
531551
 
531551
+	if (mnt_stat_mountpoint(path, &st))
531551
+		return NULL;
531551
+
531551
 	mnt = strdup(path);
531551
 	if (!mnt)
531551
 		return NULL;
531551
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
531551
index c13fb96..5c374b4 100644
531551
--- a/libmount/src/utils.c
531551
+++ b/libmount/src/utils.c
531551
@@ -104,6 +104,15 @@ static int fstype_cmp(const void *v1, const void *v2)
531551
 	return strcmp(s1, s2);
531551
 }
531551
 
531551
+int mnt_stat_mountpoint(const char *target, struct stat *st)
531551
+{
531551
+#ifdef AT_NO_AUTOMOUNT
531551
+	return fstatat(-1, target, st, AT_NO_AUTOMOUNT);
531551
+#else
531551
+	return stat(target, st);
531551
+#endif
531551
+}
531551
+
531551
 /* returns basename and keeps dirname in the @path, if @path is "/" (root)
531551
  * then returns empty string */
531551
 char *stripoff_last_component(char *path)
531551
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
531551
index fe899db..79ef12e 100644
531551
--- a/misc-utils/findmnt.c
531551
+++ b/misc-utils/findmnt.c
531551
@@ -239,16 +239,15 @@ static void set_source_match(const char *data)
531551
 /* @tb has to be from kernel (so no fstab or so)! */
531551
 static void enable_extra_target_match(struct libmnt_table *tb)
531551
 {
531551
-	char *cn = NULL;
531551
-	const char *tgt = NULL, *mnt = NULL;
531551
+	const char *tgt, *mnt = NULL;
531551
 	struct libmnt_fs *fs;
531551
 
531551
 	/*
531551
 	 * Check if match pattern is mountpoint, if not use the
531551
 	 * real mountpoint.
531551
 	 */
531551
-	cn = mnt_resolve_path(get_match(COL_TARGET), cache);
531551
-	if (!cn)
531551
+	tgt = mnt_resolve_path(get_match(COL_TARGET), cache);
531551
+	if (!tgt)
531551
 		return;
531551
 
531551
 	fs = mnt_table_find_mountpoint(tb, tgt, MNT_ITER_BACKWARD);
531551
@@ -256,9 +255,6 @@ static void enable_extra_target_match(struct libmnt_table *tb)
531551
 		mnt = mnt_fs_get_target(fs);
531551
 	if (mnt && strcmp(mnt, tgt) != 0)
531551
 		set_match(COL_TARGET, xstrdup(mnt));	/* replace the current setting */
531551
-
531551
-	/* replace the current setting with the real mountpoint */
531551
-	set_match(COL_TARGET, mnt);
531551
 }
531551
 
531551
 
531551
-- 
531551
2.7.4
531551