From: Robbie Harwood <rharwood@redhat.com>
To: keyrings@vger.kernel.org
Subject: [PATCH] keyctl: Be more friendly about invocation errors
Date: Mon, 15 Oct 2018 20:01:59 +0000 [thread overview]
Message-ID: <jlgwoqj5688.fsf@redhat.com> (raw)
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
reply other threads:[~2018-10-15 20:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=jlgwoqj5688.fsf@redhat.com \
--to=rharwood@redhat.com \
--cc=keyrings@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.