dcavalca / rpms / util-linux

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