From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v2 4/6] nfsidmap: Fix error handling in id_lookup()
Date: Wed, 05 Aug 2015 10:46:03 -0400 [thread overview]
Message-ID: <20150805144603.13266.44699.stgit@manet.1015granger.net> (raw)
In-Reply-To: <20150805143258.13266.92369.stgit@manet.1015granger.net>
As near as I can tell, the exit status of nfsidmap is supposed to be
zero (success) or one (failure).
The return value of id_lookup() becomes the exit status, so it
should return only zero or one.
The libnfsidmap calls return a signed integer, either 0 or negative
errno values. These have to be translated to an exit status.
libkeyutils calls return a signed long, either 0 or -1. These also
have to be translated to an exit status.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
utils/nfsidmap/nfsidmap.c | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c
index 65b5511..9468c08 100644
--- a/utils/nfsidmap/nfsidmap.c
+++ b/utils/nfsidmap/nfsidmap.c
@@ -186,7 +186,7 @@ static int list_keyring(const char *keyring)
/*
* Find either a user or group id based on the name@domain string
*/
-int id_lookup(char *name_at_domain, key_serial_t key, int type)
+static int id_lookup(char *name_at_domain, key_serial_t key, int type)
{
char id[MAX_ID_LEN];
uid_t uid = 0;
@@ -200,30 +200,33 @@ int id_lookup(char *name_at_domain, key_serial_t key, int type)
rc = nfs4_group_owner_to_gid(name_at_domain, &gid);
sprintf(id, "%u", gid);
}
- if (rc < 0)
+ if (rc < 0) {
xlog_errno(rc, "id_lookup: %s: failed: %m",
(type == USER ? "nfs4_owner_to_uid" : "nfs4_group_owner_to_gid"));
+ return EXIT_FAILURE;
+ }
- if (rc == 0) {
- rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
- if (rc < 0) {
- switch(rc) {
- case -EDQUOT:
- case -ENFILE:
- case -ENOMEM:
- /*
- * The keyring is full. Clear the keyring and try again
- */
- rc = keyring_clear(DEFAULT_KEYRING);
- if (rc == 0)
- rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
- break;
- default:
+ rc = EXIT_SUCCESS;
+ if (keyctl_instantiate(key, id, strlen(id) + 1, 0)) {
+ switch (errno) {
+ case EDQUOT:
+ case ENFILE:
+ case ENOMEM:
+ /*
+ * The keyring is full. Clear the keyring and try again
+ */
+ rc = keyring_clear(DEFAULT_KEYRING);
+ if (rc)
break;
+ if (keyctl_instantiate(key, id, strlen(id) + 1, 0)) {
+ rc = EXIT_FAILURE;
+ xlog_err("id_lookup: keyctl_instantiate failed: %m");
}
+ break;
+ default:
+ rc = EXIT_FAILURE;
+ break;
}
- if (rc < 0)
- xlog_err("id_lookup: keyctl_instantiate failed: %m");
}
return rc;
next prev parent reply other threads:[~2015-08-05 14:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-05 14:45 [PATCH v2 0/6] nfsidmap enhancements Chuck Lever
2015-08-05 14:45 ` [PATCH v2 1/6] nfsidmap: Display the effective NFSv4 domain name Chuck Lever
2015-08-05 14:45 ` [PATCH v2 2/6] nfsidmap: Use find_key_by_type_and_desc() if available Chuck Lever
2015-08-05 14:45 ` [PATCH v2 3/6] nfsidmap: List cached ID mapping results Chuck Lever
2015-08-05 14:46 ` Chuck Lever [this message]
2015-08-05 14:46 ` [PATCH v2 5/6] nfsidmap: Fix error handling in name_lookup() Chuck Lever
2015-08-05 14:46 ` [PATCH v2 6/6] nfsidmap: Clean up other exit status cases Chuck Lever
2015-09-16 19:08 ` [PATCH v2 0/6] nfsidmap enhancements Steve Dickson
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=20150805144603.13266.44699.stgit@manet.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.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;
as well as URLs for NNTP newsgroup(s).