All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: linux-xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] mkfs: explicitly warn about unknown token failures
Date: Mon, 18 Jun 2018 14:29:47 -0500	[thread overview]
Message-ID: <1b2f2674-d6ef-4354-057e-f476ac2e2a83@redhat.com> (raw)

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.

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) {


             reply	other threads:[~2018-06-18 19:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-18 19:29 Eric Sandeen [this message]
2018-06-19 20:03 ` [PATCH] mkfs: explicitly warn about unknown token failures Luis R. Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b2f2674-d6ef-4354-057e-f476ac2e2a83@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.