cdown / rpms / util-linux

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