aboutgitcodebugslistschat
path: root/conf.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2023-06-04 07:14:49 +0200
committerStefano Brivio <sbrivio@redhat.com>2023-06-23 10:15:55 +0200
commit3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a (patch)
treeb213e0c7ff78f7db6f9116c00d3a9c3cd417daf2 /conf.c
parentd072ac243407df464d0e0c74268631e39c5f1251 (diff)
downloadpasst-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.gz
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.bz2
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.lz
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.xz
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.tar.zst
passt-3c6d1b9bb2dd226d0ce91bd4cd6ae7eca15e387a.zip
conf, log: On -h / --help, print usage to stdout, not stderr
Erik suggests that this makes it easier to grep for options, and with --help we're anyway printing usage information as expected, not as part of an error report. While at it: on -h, we should exit with 0. Reported-by: Erik Sjölund <erik.sjolund@gmail.com> Link: https://bugs.passt.top/show_bug.cgi?id=52 Link: https://bugs.passt.top/show_bug.cgi?id=53 Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/conf.c b/conf.c
index ffff235..87dec50 100644
--- a/conf.c
+++ b/conf.c
@@ -717,10 +717,11 @@ static unsigned int conf_ip6(unsigned int ifi,
}
/**
- * usage() - Print usage and exit
+ * print_usage() - Print usage, exit with given status code
* @name: Executable name
+ * @status: Status code for exit()
*/
-static void usage(const char *name)
+static void print_usage(const char *name, int status)
{
if (strstr(name, "pasta")) {
info("Usage: %s [OPTION]... [COMMAND] [ARGS]...", name);
@@ -856,7 +857,7 @@ static void usage(const char *name)
info( " SPEC is as described for TCP above");
info( " default: none");
- exit(EXIT_FAILURE);
+ exit(status);
pasta_opts:
@@ -906,7 +907,16 @@ pasta_opts:
info( " Don't copy all addresses to namespace");
info( " --ns-mac-addr ADDR Set MAC address on tap interface");
- exit(EXIT_FAILURE);
+ exit(status);
+}
+
+/**
+ * usage() - Print usage and exit with failure
+ * @name: Executable name
+ */
+static void usage(const char *name)
+{
+ print_usage(name, EXIT_FAILURE);
}
/**
@@ -1630,8 +1640,11 @@ void conf(struct ctx *c, int argc, char **argv)
case 'U':
/* Handle these later, once addresses are configured */
break;
- case '?':
case 'h':
+ log_to_stdout = 1;
+ print_usage(argv[0], EXIT_SUCCESS);
+ break;
+ case '?':
default:
usage(argv[0]);
break;