diff mbox

mkfs: explicitly warn about unknown token failures

Message ID 1b2f2674-d6ef-4354-057e-f476ac2e2a83@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Sandeen June 18, 2018, 7:29 p.m. UTC
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>
---

I may make one more pass over all these error messages because they seem
a little hard to parse, but for now this matches the others, in general.

i.e. i'd rather have:

Invalid section "[splat]" at /etc/xfs/mkfs/default:1
...
Invalid token "foo" in section [data] at /etc/xfs/mkfs/default:2

or something like that, but I'll try to make any textual changes file-wide
if they seem warranted.


--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Luis Chamberlain June 19, 2018, 8:03 p.m. UTC | #1
On Mon, Jun 18, 2018 at 02:29:47PM -0500, Eric Sandeen wrote:
> 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>

  Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/mkfs/config.c b/mkfs/config.c
index 9954691..70d752c 100644
--- a/mkfs/config.c
+++ b/mkfs/config.c
@@ -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) {