All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: linux-nfs@vger.kernel.org
Cc: dhowells@redhat.com
Subject: [PATCH 5/6] nfsidmap: Fix error handling in name_lookup()
Date: Fri, 31 Jul 2015 15:14:14 -0700	[thread overview]
Message-ID: <20150731221414.50685.74550.stgit@seurat.1015granger.net> (raw)
In-Reply-To: <20150731220914.50685.32887.stgit@seurat.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 name_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 |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c
index 9881694..e9941b4 100644
--- a/utils/nfsidmap/nfsidmap.c
+++ b/utils/nfsidmap/nfsidmap.c
@@ -244,11 +244,10 @@ static int name_lookup(char *id, key_serial_t key, int type)
 	int rc;
 
 	rc = nfs4_get_default_domain(NULL, domain, NFS4_MAX_DOMAIN_LEN);
-	if (rc != 0) {
+	if (rc) {
 		xlog_errno(rc,
 			"name_lookup: nfs4_get_default_domain failed: %m");
-		rc = -1;
-		goto out;
+		return EXIT_FAILURE;
 	}
 
 	if (type == USER) {
@@ -258,16 +257,18 @@ static int name_lookup(char *id, key_serial_t key, int type)
 		gid = atoi(id);
 		rc = nfs4_gid_to_name(gid, domain, name, IDMAP_NAMESZ);
 	}
-	if (rc < 0)
+	if (rc) {
 		xlog_errno(rc, "name_lookup: %s: failed: %m",
 			(type == USER ? "nfs4_uid_to_name" : "nfs4_gid_to_name"));
+		return EXIT_FAILURE;
+	}
 
-	if (rc == 0) {
-		rc = keyctl_instantiate(key, &name, strlen(name), 0);
-		if (rc < 0)
-			xlog_err("name_lookup: keyctl_instantiate failed: %m");
+	rc = EXIT_SUCCESS;
+	if (keyctl_instantiate(key, &name, strlen(name), 0)) {
+		rc = EXIT_FAILURE;
+		xlog_err("name_lookup: keyctl_instantiate failed: %m");
 	}
-out:
+
 	return rc;
 }
 


  parent reply	other threads:[~2015-07-31 22:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 22:13 [PATCH 0/6] nfsidmap enhancements Chuck Lever
2015-07-31 22:13 ` [PATCH 1/6] nfsidmap: Display the effective NFSv4 domain name Chuck Lever
2015-07-31 22:13 ` [PATCH 2/6] nfsidmap: Use find_key_by_type_and_desc() if available Chuck Lever
2015-07-31 22:13 ` [PATCH 3/6] nfsidmap: List cached ID mapping results Chuck Lever
2015-08-04 13:29   ` Steve Dickson
2015-08-04 14:15     ` Chuck Lever
2015-08-04 14:30       ` Chuck Lever
2015-07-31 22:14 ` [PATCH 4/6] nfsidmap: Fix error handling in id_lookup() Chuck Lever
2015-07-31 22:14 ` Chuck Lever [this message]
2015-07-31 22:14 ` [PATCH 6/6] nfsidmap: Clean up other exit status cases Chuck Lever

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=20150731221414.50685.74550.stgit@seurat.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=dhowells@redhat.com \
    --cc=linux-nfs@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.