All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com, Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next 3/7] misc: put help to stdout and usage to stderr
Date: Fri,  7 Aug 2026 08:42:26 -0700	[thread overview]
Message-ID: <20260807154306.111200-4-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>
---
 misc/arpd.c   | 12 +++++++-----
 misc/ifstat.c | 44 ++++++++++++++++++++++----------------------
 misc/nstat.c  | 11 ++++++-----
 misc/rtacct.c | 13 ++++++-------
 4 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/misc/arpd.c b/misc/arpd.c
index a42603f6..230d3580 100644
--- a/misc/arpd.c
+++ b/misc/arpd.c
@@ -6,6 +6,7 @@
  */
 
 #include <stdio.h>
+#include <stdbool.h>
 #include <syslog.h>
 #include <malloc.h>
 #include <string.h>
@@ -88,11 +89,12 @@ int broadcast_rate = 1000;
 int broadcast_burst = 3000;
 int poll_timeout = 30000;
 
-static void usage(void)
+static void usage(bool help)
 {
-	fprintf(stderr,
+	fprintf(help ? stdout : stderr,
 		"Usage: arpd [ -lkh? ] [ -a N ] [ -b dbase ] [ -B number ] [ -f file ] [ -n time ] [-p interval ] [ -R rate ] [ interfaces ]\n");
-	exit(1);
+
+	exit(help ? 0 : 1);
 }
 
 static int handle_if(int ifindex)
@@ -594,7 +596,7 @@ int main(int argc, char **argv)
 		case 'f':
 			if (do_load) {
 				fprintf(stderr, "Duplicate option -f\n");
-				usage();
+				usage(true);
 			}
 			do_load = optarg;
 			break;
@@ -633,7 +635,7 @@ int main(int argc, char **argv)
 		case 'h':
 		case '?':
 		default:
-			usage();
+			usage(opt == 'h');
 		}
 	}
 	argc -= optind;
diff --git a/misc/ifstat.c b/misc/ifstat.c
index ec59a9eb..c2ea5942 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -756,8 +756,8 @@ static int verify_forging(int fd)
 static void xstat_usage(void)
 {
 	fprintf(stderr,
-"Usage: ifstat supported xstats:\n"
-"       cpu_hits       Counts only packets that went via the CPU.\n");
+		"Usage: ifstat supported xstats:\n"
+		"       cpu_hits       Counts only packets that went via the CPU.\n");
 }
 
 struct extended_stats_options_t {
@@ -796,27 +796,27 @@ static const char *get_filter_type(const char *name)
 	return NULL;
 }
 
-static void usage(void) __attribute__((noreturn));
+static void usage(bool help) __attribute__((noreturn));
 
-static void usage(void)
+static void usage(bool help)
 {
-	fprintf(stderr,
-"Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
-"   -h, --help           this message\n"
-"   -a, --ignore         ignore history\n"
-"   -d, --scan=SECS      sample every statistics every SECS\n"
-"   -e, --errors         show errors\n"
-"   -j, --json           format output in JSON\n"
-"   -n, --nooutput       do history only\n"
-"   -p, --pretty         pretty print\n"
-"   -r, --reset          reset history\n"
-"   -s, --noupdate       don't update history\n"
-"   -t, --interval=SECS  report average over the last SECS\n"
-"   -V, --version        output version information\n"
-"   -z, --zeros          show entries with zero activity\n"
-"   -x, --extended=TYPE  show extended stats of TYPE\n");
-
-	exit(-1);
+	fprintf(help ? stdout : stderr,
+		"Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
+		"   -h, --help           this message\n"
+		"   -a, --ignore         ignore history\n"
+		"   -d, --scan=SECS      sample every statistics every SECS\n"
+		"   -e, --errors         show errors\n"
+		"   -j, --json           format output in JSON\n"
+		"   -n, --nooutput       do history only\n"
+		"   -p, --pretty         pretty print\n"
+		"   -r, --reset          reset history\n"
+		"   -s, --noupdate       don't update history\n"
+		"   -t, --interval=SECS  report average over the last SECS\n"
+		"   -V, --version        output version information\n"
+		"   -z, --zeros          show entries with zero activity\n"
+		"   -x, --extended=TYPE  show extended stats of TYPE\n");
+
+	exit(help ? 0 : 1);
 }
 
 static const struct option longopts[] = {
@@ -898,7 +898,7 @@ int main(int argc, char *argv[])
 		case 'h':
 		case '?':
 		default:
-			usage();
+			usage(ch == 'h');
 		}
 	}
 
diff --git a/misc/nstat.c b/misc/nstat.c
index 4a9f3326..cd822ba2 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
@@ -528,11 +529,11 @@ static int verify_forging(int fd)
 	return -1;
 }
 
-static void usage(void) __attribute__((noreturn));
+static void usage(bool help) __attribute__((noreturn));
 
-static void usage(void)
+static void usage(bool help)
 {
-	fprintf(stderr,
+	fprintf(help ? stdout : stderr,
 		"Usage: nstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
 		"   -h, --help          this message\n"
 		"   -a, --ignore        ignore history\n"
@@ -545,7 +546,7 @@ static void usage(void)
 		"   -t, --interval=SECS report average over the last SECS\n"
 		"   -V, --version       output version information\n"
 		"   -z, --zeros         show entries with zero activity\n");
-	exit(-1);
+	exit(help ? 0 : 1);
 }
 
 static const struct option longopts[] = {
@@ -612,7 +613,7 @@ int main(int argc, char *argv[])
 		case 'h':
 		case '?':
 		default:
-			usage();
+			usage(ch == 'h');
 		}
 	}
 
diff --git a/misc/rtacct.c b/misc/rtacct.c
index cd84b7f0..0e2c03af 100644
--- a/misc/rtacct.c
+++ b/misc/rtacct.c
@@ -412,14 +412,13 @@ static int verify_forging(int fd)
 	return -1;
 }
 
-static void usage(void) __attribute__((noreturn));
+static void usage(bool help) __attribute__((noreturn));
 
-static void usage(void)
+static void usage(bool help)
 {
-	fprintf(stderr,
-"Usage: rtacct [ -h?vVzrnasd:t: ] [ ListOfRealms ]\n"
-		);
-	exit(-1);
+	fprintf(help ? stdout : stderr,
+		"Usage: rtacct [ -h?vVzrnasd:t: ] [ ListOfRealms ]\n");
+	exit(help ? 0 : 1);
 }
 
 int main(int argc, char *argv[])
@@ -469,7 +468,7 @@ int main(int argc, char *argv[])
 		case 'h':
 		case '?':
 		default:
-			usage();
+			usage(ch == 'h');
 		}
 	}
 
-- 
2.53.0


  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 ` Stephen Hemminger [this message]
2026-08-11 14:23   ` [PATCH iproute2-next 3/7] misc: put help to stdout and usage to stderr David Ahern
2026-08-07 15:42 ` [PATCH iproute2-next 4/7] netshaper: " Stephen Hemminger
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-4-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.