dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
531551
diff -up util-linux-2.23.2/libmount/src/tab.c.kzak util-linux-2.23.2/libmount/src/tab.c
531551
--- util-linux-2.23.2/libmount/src/tab.c.kzak	2013-07-30 10:39:26.218738358 +0200
531551
+++ util-linux-2.23.2/libmount/src/tab.c	2014-09-25 10:53:43.525269554 +0200
531551
@@ -47,6 +47,8 @@
531551
 #include "strutils.h"
531551
 #include "loopdev.h"
531551
 
531551
+static int is_mountinfo(struct libmnt_table *tb);
531551
+
531551
 /**
531551
  * mnt_new_table:
531551
  *
531551
@@ -233,7 +235,7 @@ int mnt_table_get_root_fs(struct libmnt_
531551
 	assert(tb);
531551
 	assert(root);
531551
 
531551
-	if (!tb || !root)
531551
+	if (!tb || !root || !is_mountinfo(tb))
531551
 		return -EINVAL;
531551
 
531551
 	DBG(TAB, mnt_debug_h(tb, "lookup root fs"));
531551
@@ -241,8 +243,6 @@ int mnt_table_get_root_fs(struct libmnt_
531551
 	mnt_reset_iter(&itr, MNT_ITER_FORWARD);
531551
 	while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
531551
 		int id = mnt_fs_get_parent_id(fs);
531551
-		if (!id)
531551
-			break;		/* @tab is not mountinfo file? */
531551
 
531551
 		if (!*root || id < root_id) {
531551
 			*root = fs;
531551
@@ -250,7 +250,7 @@ int mnt_table_get_root_fs(struct libmnt_
531551
 		}
531551
 	}
531551
 
531551
-	return root_id ? 0 : -EINVAL;
531551
+	return *root ? 0 : -EINVAL;
531551
 }
531551
 
531551
 /**
531551
@@ -271,15 +271,13 @@ int mnt_table_next_child_fs(struct libmn
531551
 	struct libmnt_fs *fs;
531551
 	int parent_id, lastchld_id = 0, chld_id = 0;
531551
 
531551
-	if (!tb || !itr || !parent)
531551
+	if (!tb || !itr || !parent || !is_mountinfo(tb))
531551
 		return -EINVAL;
531551
 
531551
 	DBG(TAB, mnt_debug_h(tb, "lookup next child of '%s'",
531551
 				mnt_fs_get_target(parent)));
531551
 
531551
 	parent_id = mnt_fs_get_id(parent);
531551
-	if (!parent_id)
531551
-		return -EINVAL;
531551
 
531551
 	/* get ID of the previously returned child */
531551
 	if (itr->head && itr->p != itr->head) {
531551
@@ -310,7 +308,7 @@ int mnt_table_next_child_fs(struct libmn
531551
 		}
531551
 	}
531551
 
531551
-	if (!chld_id)
531551
+	if (!*chld)
531551
 		return 1;	/* end of iterator */
531551
 
531551
 	/* set the iterator to the @chld for the next call */
531551
diff -up util-linux-2.23.2/misc-utils/findmnt.c.kzak util-linux-2.23.2/misc-utils/findmnt.c
531551
--- util-linux-2.23.2/misc-utils/findmnt.c.kzak	2013-07-30 11:07:35.138395654 +0200
531551
+++ util-linux-2.23.2/misc-utils/findmnt.c	2014-09-25 10:49:50.953050560 +0200
531551
@@ -826,8 +826,9 @@ static int tab_is_tree(struct libmnt_tab
531551
 	if (!itr)
531551
 		return 0;
531551
 
531551
-	if (mnt_table_next_fs(tb, itr, &fs) == 0)
531551
-		rc = mnt_fs_get_id(fs) > 0 && mnt_fs_get_parent_id(fs) > 0;
531551
+	rc = (mnt_table_next_fs(tb, itr, &fs) == 0 &&
531551
+	      mnt_fs_is_kernel(fs) &&
531551
+	      mnt_fs_get_root(fs));
531551
 
531551
 	mnt_free_iter(itr);
531551
 	return rc;