netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, dsahern@gmail.com
Subject: [patch iproute2-next 3/6] devlink: implement command line args dry parsing
Date: Thu, 31 Aug 2023 15:22:26 +0200	[thread overview]
Message-ID: <20230831132229.471693-4-jiri@resnulli.us> (raw)
In-Reply-To: <20230831132229.471693-1-jiri@resnulli.us>

From: Jiri Pirko <jiri@nvidia.com>

In preparation to the follow-up dump selector patch, introduce function
dl_argv_dry_parse() which allows to do dry parsing of command line
arguments without printing out any error messages to the user.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 devlink/devlink.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index e7b5b788863a..8d2424f58cc2 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -64,6 +64,7 @@
 static int g_new_line_count;
 static int g_indent_level;
 static bool g_indent_newline;
+static bool g_err_suspended;
 
 #define INDENT_STR_STEP 2
 #define INDENT_STR_MAXLEN 32
@@ -74,6 +75,8 @@ pr_err(const char *fmt, ...)
 {
 	va_list ap;
 
+	if (g_err_suspended)
+		return;
 	va_start(ap, fmt);
 	vfprintf(stderr, fmt, ap);
 	va_end(ap);
@@ -2284,6 +2287,21 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
 	return dl_args_finding_required_validate(o_required, o_found);
 }
 
+static int dl_argv_dry_parse(struct dl *dl, uint64_t o_required,
+			     uint64_t o_optional)
+{
+	char **argv = dl->argv;
+	int argc = dl->argc;
+	int err;
+
+	g_err_suspended = true;
+	err = dl_argv_parse(dl, o_required, o_optional);
+	g_err_suspended = false;
+	dl->argv = argv;
+	dl->argc = argc;
+	return err;
+}
+
 static void
 dl_function_attr_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
 {
-- 
2.41.0


  parent reply	other threads:[~2023-08-31 13:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 13:22 [patch iproute2-next 0/6] devlink: implement dump selector for devlink objects show commands Jiri Pirko
2023-08-31 13:22 ` [patch iproute2-next 1/6] devlink: move DL_OPT_SB into required options Jiri Pirko
2023-08-31 13:22 ` [patch iproute2-next 2/6] devlink: make parsing of handle non-destructive to argv Jiri Pirko
2023-08-31 13:22 ` Jiri Pirko [this message]
2023-08-31 13:22 ` [patch iproute2-next 4/6] devlink: return -ENOENT if argument is missing Jiri Pirko
2023-08-31 13:22 ` [patch iproute2-next 5/6] mnl_utils: introduce a helper to check if dump policy exists for command Jiri Pirko
2023-08-31 13:22 ` [patch iproute2-next 6/6] devlink: implement dump selector for devlink objects show commands Jiri Pirko
2023-09-04  9:33 ` [patch iproute2-next 0/6] " Jiri Pirko

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=20230831132229.471693-4-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).