* [PATCH] keyctl: Be more friendly about invocation errors
@ 2018-10-15 20:01 Robbie Harwood
0 siblings, 0 replies; only message in thread
From: Robbie Harwood @ 2018-10-15 20:01 UTC (permalink / raw)
To: keyrings
From 901cc5241e4a66168aed4998077d8fbe39efa866 Mon Sep 17 00:00:00 2001
From: Robbie Harwood <rharwood@redhat.com>
Date: Mon, 15 Oct 2018 15:57:51 -0400
Subject: [PATCH] keyctl: Be more friendly about invocation errors
When option parsing fails in main(), display usage information.
Also cleanly handle `keyctl --help`.
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
keyctl.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/keyctl.c b/keyctl.c
index 61990b4..406f216 100644
--- a/keyctl.c
+++ b/keyctl.c
@@ -31,6 +31,7 @@ struct command {
#define nr __attribute__((noreturn))
static nr void act_keyctl___version(int argc, char *argv[]);
+static nr void act_keyctl___help(int argc, char *argv[]);
static nr void act_keyctl_show(int argc, char *argv[]);
static nr void act_keyctl_add(int argc, char *argv[]);
static nr void act_keyctl_padd(int argc, char *argv[]);
@@ -74,6 +75,7 @@ static nr void act_keyctl_restrict_keyring(int argc, char *argv[]);
const struct command commands[] = {
{ act_keyctl___version, "--version", "" },
+ { act_keyctl___help, "--help", "" },
{ act_keyctl_add, "add", "<type> <desc> <data> <keyring>" },
{ act_keyctl_chgrp, "chgrp", "<key> <gid>" },
{ act_keyctl_chown, "chown", "<key> <uid>" },
@@ -178,7 +180,7 @@ int main(int argc, char *argv[])
/* partial match */
if (best) {
fprintf(stderr, "Ambiguous command\n");
- exit(2);
+ format();
}
best = cmd;
@@ -186,7 +188,7 @@ int main(int argc, char *argv[])
if (!best) {
fprintf(stderr, "Unknown command\n");
- exit(2);
+ format();
}
best->action(argc, argv);
@@ -235,6 +237,15 @@ static void act_keyctl___version(int argc, char *argv[])
exit(0);
}
+/*****************************************************************************/
+/*
+ * Display help text (wrapper)
+ */
+static void act_keyctl___help(int argc, char *argv[])
+{
+ format();
+}
+
/*****************************************************************************/
/*
* grab data from stdin
--
2.19.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-10-15 20:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-15 20:01 [PATCH] keyctl: Be more friendly about invocation errors Robbie Harwood
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.