b394b9
From 28663e752e125da99f8636ea0227d168f1e0e6aa Mon Sep 17 00:00:00 2001
b394b9
From: Karel Zak <kzak@redhat.com>
b394b9
Date: Thu, 15 Oct 2015 11:53:44 +0200
b394b9
Subject: [PATCH 62/84] mount, umount, swapon, fsck, lsblk, findmnt: ignore
b394b9
 malformed lines
b394b9
b394b9
The libmount provides way how to deal with parsing errors in fstab --
b394b9
on error callback function is executed and according to the return
b394b9
libmount manipulate with the malformed line, possible are three
b394b9
states:
b394b9
b394b9
  1/ fatal error; all file ignored              (callback rc < 0)
b394b9
  2/ recoverable error; malformed line ignored  (callback rc > 0)
b394b9
  3/ ignore the error                           (callback rc == 0)
b394b9
b394b9
The 2/ is the default if no callback specified.
b394b9
b394b9
Unfortunately our utils uses 3/. The correct way is to use 2/.
b394b9
b394b9
Upstream: http://github.com/karelzak/util-linux/commit/1cd9d0d7463850ef6b16a78b8a55e56dbf9a8db1
b394b9
Upstream: http://github.com/karelzak/util-linux/commit/1bb02a2da9f1bf7d80b352d540b29371099ab570
b394b9
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1271850
b394b9
Signed-off-by: Karel Zak <kzak@redhat.com>
b394b9
---
b394b9
 disk-utils/fsck.c         |  2 +-
b394b9
 libmount/src/tab_parse.c  |  2 +-
b394b9
 misc-utils/findmnt.c      |  2 +-
b394b9
 misc-utils/lsblk.c        | 11 +++++++++++
b394b9
 sys-utils/mount.c         |  2 +-
b394b9
 sys-utils/swapon-common.c | 11 +++++++++++
b394b9
 sys-utils/umount.c        |  2 +-
b394b9
 7 files changed, 27 insertions(+), 5 deletions(-)
b394b9
b394b9
diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c
b394b9
index 6e3a2c0..3ef8e5b 100644
b394b9
--- a/disk-utils/fsck.c
b394b9
+++ b/disk-utils/fsck.c
b394b9
@@ -421,7 +421,7 @@ static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
b394b9
 			const char *filename, int line)
b394b9
 {
b394b9
 	warnx(_("%s: parse error at line %d -- ignore"), filename, line);
b394b9
-	return 0;
b394b9
+	return 1;
b394b9
 }
b394b9
 
b394b9
 /*
b394b9
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
b394b9
index e930fd8..987e671 100644
b394b9
--- a/libmount/src/tab_parse.c
b394b9
+++ b/libmount/src/tab_parse.c
b394b9
@@ -540,7 +540,7 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam
b394b9
 		}
b394b9
 		if (rc) {
b394b9
 			mnt_free_fs(fs);
b394b9
-			if (rc == 1)
b394b9
+			if (rc > 0)
b394b9
 				continue;	/* recoverable error */
b394b9
 			if (feof(f))
b394b9
 				break;
b394b9
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
b394b9
index 615ba08..f16da91 100644
b394b9
--- a/misc-utils/findmnt.c
b394b9
+++ b/misc-utils/findmnt.c
b394b9
@@ -752,7 +752,7 @@ static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
b394b9
 			const char *filename, int line)
b394b9
 {
b394b9
 	warnx(_("%s: parse error at line %d"), filename, line);
b394b9
-	return 0;
b394b9
+	return 1;
b394b9
 }
b394b9
 
b394b9
 static char **append_tabfile(char **files, int *nfiles, char *filename)
b394b9
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
b394b9
index 9e12a90..cd28c1d 100644
b394b9
--- a/misc-utils/lsblk.c
b394b9
+++ b/misc-utils/lsblk.c
b394b9
@@ -337,6 +337,15 @@ static char *get_device_path(struct blkdev_cxt *cxt)
b394b9
 	return xstrdup(path);
b394b9
 }
b394b9
 
b394b9
+static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)),
b394b9
+			const char *filename, int line)
b394b9
+{
b394b9
+	if (filename)
b394b9
+		warnx(_("%s: parse error: ignore entry at line %d."),
b394b9
+							filename, line);
b394b9
+	return 1;
b394b9
+}
b394b9
+
b394b9
 static int is_active_swap(const char *filename)
b394b9
 {
b394b9
 	if (!swaps) {
b394b9
@@ -346,6 +355,7 @@ static int is_active_swap(const char *filename)
b394b9
 		if (!mntcache)
b394b9
 			mntcache = mnt_new_cache();
b394b9
 
b394b9
+		mnt_table_set_parser_errcb(swaps, table_parser_errcb);
b394b9
 		mnt_table_set_cache(swaps, mntcache);
b394b9
 		mnt_table_parse_swaps(swaps, NULL);
b394b9
 	}
b394b9
@@ -368,6 +378,7 @@ static char *get_device_mountpoint(struct blkdev_cxt *cxt)
b394b9
 		if (!mntcache)
b394b9
 			mntcache = mnt_new_cache();
b394b9
 
b394b9
+		mnt_table_set_parser_errcb(mtab, table_parser_errcb);
b394b9
 		mnt_table_set_cache(mtab, mntcache);
b394b9
 		mnt_table_parse_mtab(mtab, NULL);
b394b9
 	}
b394b9
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
b394b9
index 0998b01..f332070 100644
b394b9
--- a/sys-utils/mount.c
b394b9
+++ b/sys-utils/mount.c
b394b9
@@ -101,7 +101,7 @@ static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)
b394b9
 	if (filename)
b394b9
 		warnx(_("%s: parse error: ignore entry at line %d."),
b394b9
 							filename, line);
b394b9
-	return 0;
b394b9
+	return 1;
b394b9
 }
b394b9
 
b394b9
 /*
b394b9
diff --git a/sys-utils/swapon-common.c b/sys-utils/swapon-common.c
b394b9
index 5c95ef3..5f14ddb 100644
b394b9
--- a/sys-utils/swapon-common.c
b394b9
+++ b/sys-utils/swapon-common.c
b394b9
@@ -11,12 +11,22 @@ static struct libmnt_table *swaps, *fstab;
b394b9
 
b394b9
 struct libmnt_cache *mntcache;
b394b9
 
b394b9
+static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)),
b394b9
+			const char *filename, int line)
b394b9
+{
b394b9
+	if (filename)
b394b9
+		warnx(_("%s: parse error: ignore entry at line %d."),
b394b9
+							filename, line);
b394b9
+	return 1;
b394b9
+}
b394b9
+
b394b9
 struct libmnt_table *get_fstab(void)
b394b9
 {
b394b9
 	if (!fstab) {
b394b9
 		fstab = mnt_new_table();
b394b9
 		if (!fstab)
b394b9
 			return NULL;
b394b9
+		mnt_table_set_parser_errcb(fstab, table_parser_errcb);
b394b9
 		mnt_table_set_cache(fstab, mntcache);
b394b9
 		if (mnt_table_parse_fstab(fstab, NULL) != 0)
b394b9
 			return NULL;
b394b9
@@ -32,6 +42,7 @@ struct libmnt_table *get_swaps(void)
b394b9
 		if (!swaps)
b394b9
 			return NULL;
b394b9
 		mnt_table_set_cache(swaps, mntcache);
b394b9
+		mnt_table_set_parser_errcb(swaps, table_parser_errcb);
b394b9
 		if (mnt_table_parse_swaps(swaps, NULL) != 0)
b394b9
 			return NULL;
b394b9
 	}
b394b9
diff --git a/sys-utils/umount.c b/sys-utils/umount.c
b394b9
index 1bd275f..9c47744 100644
b394b9
--- a/sys-utils/umount.c
b394b9
+++ b/sys-utils/umount.c
b394b9
@@ -45,7 +45,7 @@ static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)
b394b9
 	if (filename)
b394b9
 		warnx(_("%s: parse error: ignore entry at line %d."),
b394b9
 							filename, line);
b394b9
-	return 0;
b394b9
+	return 1;
b394b9
 }
b394b9
 
b394b9
 
b394b9
-- 
b394b9
2.7.4
b394b9