public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Yedaya Katsman <yedaya.ka@gmail.com>
Cc: David Ahern <dsahern@kernel.org>, Petr Machata <petrm@nvidia.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH] ip: Make 'ip stats help' exit with -1
Date: Sun, 1 Mar 2026 10:36:22 -0800	[thread overview]
Message-ID: <20260301103622.44ef19d7@phoenix.local> (raw)
In-Reply-To: <20260301-ip-stats-exit-code-v1-1-2b59f0704f2c@gmail.com>

On Sun, 01 Mar 2026 16:12:03 +0200
Yedaya Katsman <yedaya.ka@gmail.com> wrote:

> ip <subcommand> help exits with -1 for all commands except for stats, make
> it match.
> This removes a goto err, which is redundant since "enabled" gets
> allocated only if we find a level, but we enter do_help only if we didn't.
> 
> Fixes: df0b2c6d0098 ("ipstats: Add a shell of "show" command")
> Signed-off-by: Yedaya Katsman <yedaya.ka@gmail.com>

You raise a good point, but not sure that fixing just one corner is the
right answer here. Most of iproute2 gets this wrong already.

The (poorly documented) convention for help in Unix commands:
Output destination: stdout (not stderr). 
Help text is expected, requested output — not an error.
This matters for piping, e.g. command --help | grep something.

Exit code: 0 (success).
The user asked for help and got it — that's a successful operation.

Contrast with error cases:
When a user provides an invalid flag or misuses the command, 
the usage/error message should go to stderr with a non-zero exit code
(typically 1 or 2 — 2 is common convention from many GNU tools for usage errors).

In practice, this is codified in the GNU Coding Standards, 
which explicitly state that --help should print to stdout and exit with status 0.
POSIX doesn't mandate -h specifically, but the GNU convention is widely followed and expected.
A surprising number of tools historically got this wrong (sending help to stderr or returning non-zero).

But iproute2 does not follow this convention.
Fixing it might be a good idea, the kind of thing AI refactoring might help at.

An example which should print nothing!
$ ip help >/dev/null || echo broken 
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { address | addrlabel | fou | help | ila | ioam | l2tp | link |
                   macsec | maddress | monitor | mptcp | mroute | mrule |
                   neighbor | neighbour | netconf | netns | nexthop | ntable |
                   ntbl | route | rule | sr | stats | tap | tcpmetrics |
                   token | tunnel | tuntap | vrf | xfrm }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec | -j[son] | -p[retty] |
                    -f[amily] { inet | inet6 | mpls | bridge | link } |
                    -4 | -6 | -M | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } | -echo | -br[ief] |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |
                    -c[olor]}
broken



      reply	other threads:[~2026-03-01 18:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-01 14:12 [PATCH] ip: Make 'ip stats help' exit with -1 Yedaya Katsman
2026-03-01 18:36 ` Stephen Hemminger [this message]

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=20260301103622.44ef19d7@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=petrm@nvidia.com \
    --cc=yedaya.ka@gmail.com \
    /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