]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: explicitly warn about unknown config token failures
authorEric Sandeen <sandeen@redhat.com>
Tue, 19 Jun 2018 20:43:04 +0000 (15:43 -0500)
committerEric Sandeen <sandeen@redhat.com>
Tue, 19 Jun 2018 20:43:04 +0000 (15:43 -0500)
Rather than a generic "Error parsing line" for an unknown token
within a section, issue a more helpful error message, i.e.

[data]
foo=1

would yield:

Invalid token in section [data] at line /etc/xfs/mkfs/default:2 : foo

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/config.c

index 9954691b09709f2cd3597c62ba129398fa130cc7..70d752ce028283c4a9d689ba884eed068746df14 100644 (file)
@@ -466,9 +466,6 @@ _("No section specified yet on line %s:%zu : %s\n"),
                         */
                        snprintf(p, len, "%s=%lu", tag, value);
 
-                       /* Not needed anymore */
-                       free(tag);
-
                        /*
                         * We only use getsubopt() to validate the possible
                         * subopt, we already parsed the value and its already
@@ -476,6 +473,16 @@ _("No section specified yet on line %s:%zu : %s\n"),
                         */
                        subopt = getsubopt(&p, (char **) confopt->subopts,
                                           &ignore_value);
+                       if (subopt == -1) {
+                               errno = EINVAL;
+                               fprintf(stderr,
+_("Invalid token in section [%s] at line %s:%zu : %s\n"),
+                                       confopt->name, config_file, lineno, tag);
+                               goto out_free_tag;
+                       }
+
+                       /* Not needed anymore */
+                       free(tag);
 
                        ret = confopt->parser(dft, subopt, value);
                        if (ret) {