* [PATCH iproute2] ip: return correct status from help command
@ 2026-06-21 18:03 Rose Wright
2026-06-22 15:16 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Rose Wright @ 2026-06-21 18:03 UTC (permalink / raw)
To: netdev; +Cc: stephen, Rose Wright
Currently, "ip help" or "ip -help" always returns an error code because usage() is used as a fall through on "ip" and defaults to stderr with -1.
This is a minor bug that breaks "ip help | grep" and other scripts that rely on standard exit codes. The fix is to pass the status code as a parameter into usage() and change stderr to stdout when needed.
Signed-off-by: Rose Wright <rosesophiewright@gmail.com>
---
ip/ip.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/ip/ip.c b/ip/ip.c
index e4b71bde..ee4595e8 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -52,11 +52,12 @@ const char *get_ip_lib_dir(void)
return lib_dir;
}
-static void usage(void) __attribute__((noreturn));
+static void usage(int status) __attribute__((noreturn));
-static void usage(void)
+static void usage(int status)
{
- fprintf(stderr,
+ FILE *out = status == 0 ? stdout : stderr;
+ fprintf(out,
"Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n"
" ip [ -force ] -batch filename\n"
"where OBJECT := { address | addrlabel | fou | help | ila | ioam | l2tp | link |\n"
@@ -72,12 +73,12 @@ static void usage(void)
" -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n"
" -rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |\n"
" -c[olor]}\n");
- exit(-1);
+ exit(status);
}
static int do_help(int argc, char **argv)
{
- usage();
+ usage(0);
return 0;
}
@@ -279,7 +280,7 @@ int main(int argc, char **argv)
rcvbuf = size;
} else if (matches_color(opt, &color)) {
} else if (matches(opt, "-help") == 0) {
- usage();
+ usage(0);
} else if (matches(opt, "-netns") == 0) {
NEXT_ARG();
if (netns_switch(argv[1]))
@@ -321,5 +322,5 @@ int main(int argc, char **argv)
return do_cmd(argv[1], argc-1, argv+1, true);
rtnl_close(&rth);
- usage();
+ usage(-1);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2] ip: return correct status from help command
2026-06-21 18:03 [PATCH iproute2] ip: return correct status from help command Rose Wright
@ 2026-06-22 15:16 ` Stephen Hemminger
2026-06-22 17:18 ` Rose
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2026-06-22 15:16 UTC (permalink / raw)
To: Rose Wright; +Cc: netdev
On Sun, 21 Jun 2026 18:03:11 +0000
Rose Wright <rosesophiewright@gmail.com> wrote:
> Currently, "ip help" or "ip -help" always returns an error code because usage() is used as a fall through on "ip" and defaults to stderr with -1.
>
> This is a minor bug that breaks "ip help | grep" and other scripts that rely on standard exit codes. The fix is to pass the status code as a parameter into usage() and change stderr to stdout when needed.
>
> Signed-off-by: Rose Wright <rosesophiewright@gmail.com>
> ---
This is the closest of the three submissions, but there are way more commands in iproute2
than just ip. Need to address all the commands. Looks like perfect trivial job for AI
coding tools. I am looking into it now.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2] ip: return correct status from help command
2026-06-22 15:16 ` Stephen Hemminger
@ 2026-06-22 17:18 ` Rose
0 siblings, 0 replies; 3+ messages in thread
From: Rose @ 2026-06-22 17:18 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Hi Stephen,
Thanks for the feedback. I'd love to finish this up. I can apply the
same fix to the other commands in iproute2 sometime after work, around
17:30 UTC today.
Thanks again,
Rose
On Mon, Jun 22, 2026 at 10:16 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Sun, 21 Jun 2026 18:03:11 +0000
> Rose Wright <rosesophiewright@gmail.com> wrote:
>
> > Currently, "ip help" or "ip -help" always returns an error code because usage() is used as a fall through on "ip" and defaults to stderr with -1.
> >
> > This is a minor bug that breaks "ip help | grep" and other scripts that rely on standard exit codes. The fix is to pass the status code as a parameter into usage() and change stderr to stdout when needed.
> >
> > Signed-off-by: Rose Wright <rosesophiewright@gmail.com>
> > ---
>
> This is the closest of the three submissions, but there are way more commands in iproute2
> than just ip. Need to address all the commands. Looks like perfect trivial job for AI
> coding tools. I am looking into it now.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-22 17:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-21 18:03 [PATCH iproute2] ip: return correct status from help command Rose Wright
2026-06-22 15:16 ` Stephen Hemminger
2026-06-22 17:18 ` Rose
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.