]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mount, umount, swapon, fsck, lsblk, findmnt: ignore malformed lines
authorKarel Zak <kzak@redhat.com>
Thu, 15 Oct 2015 09:53:44 +0000 (11:53 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 15 Oct 2015 10:01:48 +0000 (12:01 +0200)
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 <kzak@redhat.com>
disk-utils/fsck.c
misc-utils/findmnt.c
misc-utils/lsblk.c
sys-utils/mount.c
sys-utils/swapon-common.c
sys-utils/umount.c

index a103408ef253958f8fd6e736b35465309d796a55..ff504aa1da5fa3552595585d35a8a28469b7a6fe 100644 (file)
@@ -471,7 +471,7 @@ static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
                        const char *filename, int line)
 {
        warnx(_("%s: parse error at line %d -- ignore"), filename, line);
-       return 0;
+       return 1;
 }
 
 /*
index 8218464b491de13fb105b6c52486584b50773c52..dd84671dcc1d8dbc6dcf02f2535c650b3ca05610 100644 (file)
@@ -805,7 +805,7 @@ static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
                        const char *filename, int line)
 {
        warnx(_("%s: parse error at line %d"), filename, line);
-       return 0;
+       return 1;
 }
 
 static char **append_tabfile(char **files, int *nfiles, char *filename)
index d1bb13a546a2300d6e44f3f9ffb587e3686de771..2604e84c26d8967208e5940302d482789290e592 100644 (file)
@@ -426,6 +426,15 @@ static char *get_device_path(struct blkdev_cxt *cxt)
        return xstrdup(path);
 }
 
+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;
+}
+
 static int is_active_swap(const char *filename)
 {
        if (!swaps) {
@@ -435,6 +444,7 @@ static int is_active_swap(const char *filename)
                if (!mntcache)
                        mntcache = mnt_new_cache();
 
+               mnt_table_set_parser_errcb(swaps, table_parser_errcb);
                mnt_table_set_cache(swaps, mntcache);
                mnt_table_parse_swaps(swaps, NULL);
        }
@@ -457,6 +467,7 @@ static char *get_device_mountpoint(struct blkdev_cxt *cxt)
                if (!mntcache)
                        mntcache = mnt_new_cache();
 
+               mnt_table_set_parser_errcb(mtab, table_parser_errcb);
                mnt_table_set_cache(mtab, mntcache);
                mnt_table_parse_mtab(mtab, NULL);
        }
index c22c8c996254e6b9558021609b7761da786030a7..73f9d0b655872cdc97d1fce85030289292e2eb6b 100644 (file)
@@ -101,7 +101,7 @@ static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)
        if (filename)
                warnx(_("%s: parse error: ignore entry at line %d."),
                                                        filename, line);
-       return 0;
+       return 1;
 }
 
 /*
index 8f7788cb03515de59787b922a04f579989ee454c..75466a056bece2c767cbd54898cce020e124b027 100644 (file)
@@ -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;
        }
index 464c4c87f4dbc34bf302ff955ec9158d80b271b2..1d866fa1a7f448757e23790ce6b7f4537cdeb427 100644 (file)
@@ -45,7 +45,7 @@ static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)
        if (filename)
                warnx(_("%s: parse error: ignore entry at line %d."),
                                                        filename, line);
-       return 0;
+       return 1;
 }