From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com, Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next 4/7] netshaper: put help to stdout and usage to stderr
Date: Fri, 7 Aug 2026 08:42:27 -0700 [thread overview]
Message-ID: <20260807154306.111200-5-stephen@networkplumber.org> (raw)
In-Reply-To: <20260807154306.111200-1-stephen@networkplumber.org>
Similar change to other iproute2 commands.
Syntax error should print to stderr and exit with non-zero.
Help command should print to stdout and exit with zero status.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
netshaper/netshaper.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/netshaper/netshaper.c b/netshaper/netshaper.c
index 3b47d43d..85999dd5 100644
--- a/netshaper/netshaper.c
+++ b/netshaper/netshaper.c
@@ -26,9 +26,11 @@
static struct rtnl_handle gen_rth = { .fd = -1 };
static int genl_family = -1;
-static void usage(void)
+static void usage(bool help) __attribute__((noreturn));
+
+static void usage(bool help)
{
- fprintf(stderr,
+ fprintf(help ? stdout : stderr,
"Usage: netshaper [ OPTIONS ] { COMMAND | help }\n"
"OPTIONS := { -V[ersion] | -c[olor] | -help }\n"
"COMMAND := { set | get | delete | group } dev DEVNAME\n"
@@ -46,6 +48,8 @@ static void usage(void)
" HANDLE_ID := UINT (required for queue/node, optional for netdev)\n"
" BW_MIN/BW_MAX := UINT{ kbit | mbit | gbit }\n"
" WEIGHT := UINT\n");
+
+ exit(help ? EXIT_SUCCESS : EXIT_FAILURE);
}
static const char *net_shaper_scope_names[NET_SHAPER_SCOPE_MAX + 1] = {
@@ -243,7 +247,7 @@ static int do_cmd(int argc, char **argv, int cmd)
if (strcmp(*argv, "scope") != 0) {
fprintf(stderr, "What is \"%s\"\n", *argv);
- usage();
+ usage(false);
return -1;
}
NEXT_ARG();
@@ -270,7 +274,7 @@ static int do_cmd(int argc, char **argv, int cmd)
NEXT_ARG();
if (strcmp(*argv, "id") != 0) {
fprintf(stderr, "What is \"%s\"\n", *argv);
- usage();
+ usage(false);
return -1;
}
NEXT_ARG();
@@ -282,7 +286,7 @@ static int do_cmd(int argc, char **argv, int cmd)
}
} else {
fprintf(stderr, "What is \"%s\"\n", *argv);
- usage();
+ usage(false);
return -1;
}
argc--;
@@ -363,7 +367,7 @@ static int parse_scope_id(const char *what, int *argcp, char ***argvp, int *scop
NEXT_ARG();
if (strcmp(*argv, "id") != 0) {
fprintf(stderr, "What is \"%s\"\n", *argv);
- usage();
+ usage(false);
return -1;
}
NEXT_ARG();
@@ -517,7 +521,7 @@ static int do_group(int argc, char **argv)
continue;
} else {
fprintf(stderr, "What is \"%s\"\n", *argv);
- usage();
+ usage(false);
goto free_leaves;
}
argc--;
@@ -609,8 +613,7 @@ int main(int argc, char **argv)
opt++;
if (strcmp(opt, "-help") == 0) {
- usage();
- exit(0);
+ usage(true);
} else if (strcmp(opt, "-Version") == 0 ||
strcmp(opt, "-V") == 0) {
printf("netshaper utility, %s\n", version);
@@ -627,6 +630,9 @@ int main(int argc, char **argv)
check_enable_color(color, 0);
+ if (argc > 1 && strcmp(argv[1], "help") == 0)
+ usage(true);
+
if (genl_init_handle(&gen_rth, NET_SHAPER_FAMILY_NAME, &genl_family))
exit(1);
@@ -642,15 +648,10 @@ int main(int argc, char **argv)
return do_cmd(argc - 1, argv + 1, NET_SHAPER_CMD_GET);
if (strcmp(*argv, "group") == 0)
return do_group(argc - 1, argv + 1);
- if (strcmp(*argv, "help") == 0) {
- usage();
- return 0;
- }
fprintf(stderr,
"Command \"%s\" is unknown, try \"netshaper help\".\n",
*argv);
exit(-1);
}
- usage();
- exit(-1);
+ usage(false);
}
--
2.53.0
next prev parent reply other threads:[~2026-08-07 15:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 15:42 [PATCH iproute2-next 0/7] cleanup help and exit codes Stephen Hemminger
2026-08-07 15:42 ` [PATCH iproute2-next 1/7] ip: follow Linux convention for help vs usage Stephen Hemminger
2026-08-07 15:42 ` [PATCH iproute2-next 2/7] ip/routel: follow help vs usage convention Stephen Hemminger
2026-08-07 15:42 ` [PATCH iproute2-next 3/7] misc: put help to stdout and usage to stderr Stephen Hemminger
2026-08-11 14:23 ` David Ahern
2026-08-07 15:42 ` Stephen Hemminger [this message]
2026-08-07 15:42 ` [PATCH iproute2-next 5/7] bridge: " Stephen Hemminger
2026-08-07 15:42 ` [PATCH iproute2-next 6/7] genl: " Stephen Hemminger
2026-08-07 15:42 ` [PATCH iproute2-next 7/7] tc: " Stephen Hemminger
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=20260807154306.111200-5-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dsahern@gmail.com \
--cc=netdev@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.