dcavalca / rpms / util-linux

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