From 1cd9d0d7463850ef6b16a78b8a55e56dbf9a8db1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 15 Oct 2015 11:53:44 +0200 Subject: mount, umount, swapon, fsck, lsblk, findmnt: ignore malformed lines The libmount provides way how to deal with parsing errors in fstab -- on error callback function is executed and according to the return libmount manipulate with the malformed line, possible are three states: 1/ fatal error; all file ignored (callback rc < 0) 2/ recoverable error; malformed line ignored (callback rc > 0) 3/ ignore the error (callback rc == 0) The 2/ is the default if no callback specified. Unfortunately our utils uses 3/. The correct way is to use 2/. Signed-off-by: Karel Zak --- sys-utils/swapon-common.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sys-utils/swapon-common.c') diff --git a/sys-utils/swapon-common.c b/sys-utils/swapon-common.c index 8f7788cb0..75466a056 100644 --- a/sys-utils/swapon-common.c +++ b/sys-utils/swapon-common.c @@ -12,12 +12,22 @@ static struct libmnt_table *swaps, *fstab; struct libmnt_cache *mntcache; +static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)), + const char *filename, int line) +{ + if (filename) + warnx(_("%s: parse error: ignore entry at line %d."), + filename, line); + return 1; +} + struct libmnt_table *get_fstab(void) { if (!fstab) { fstab = mnt_new_table(); if (!fstab) return NULL; + mnt_table_set_parser_errcb(fstab, table_parser_errcb); mnt_table_set_cache(fstab, mntcache); if (mnt_table_parse_fstab(fstab, NULL) != 0) return NULL; @@ -33,6 +43,7 @@ struct libmnt_table *get_swaps(void) if (!swaps) return NULL; mnt_table_set_cache(swaps, mntcache); + mnt_table_set_parser_errcb(swaps, table_parser_errcb); if (mnt_table_parse_swaps(swaps, NULL) != 0) return NULL; } -- cgit v1.2.3-55-g7522