All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Steve Dickson <SteveD@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 4/4 revised] Remove error messages on xstrdup failure.
Date: Fri, 02 Dec 2016 14:26:56 +1100	[thread overview]
Message-ID: <878trz6mf3.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <148064098431.9179.10389198547881177509.stgit@noble>

[-- Attachment #1: Type: text/plain, Size: 3956 bytes --]


xstrdup() prints a messages and exits, except in statd where is prints
a message and fails.
So there is no point printing an extra message when xstrdup() fails,
and except in statd, no point calling exit() as well.

So remove some pointless code.

Signed-off-by: NeilBrown <neilb@suse.com>
---

Sorry, missed an include file in nfsd.c
The output of 'make' is too noisy :-(
It is easy to miss things (and something about bad workmen and tools).
NeilBrown


 utils/mountd/mountd.c     |  6 +-----
 utils/nfsd/nfsd.c         | 35 ++++++-----------------------------
 utils/nfsidmap/nfsidmap.c |  6 +-----
 utils/statd/statd.c       |  5 +----
 4 files changed, 9 insertions(+), 43 deletions(-)

diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
index a0ab2935136a..d6cebbbd3920 100644
--- a/utils/mountd/mountd.c
+++ b/utils/mountd/mountd.c
@@ -721,11 +721,7 @@ main(int argc, char **argv)
 			reverse_resolve = 1;
 			break;
 		case 's':
-			if ((state_dir = xstrdup(optarg)) == NULL) {
-				fprintf(stderr, "%s: xstrdup(%s) failed!\n",
-					progname, optarg);
-				exit(1);
-			}
+			state_dir = xstrdup(optarg);
 			break;
 		case 't':
 			num_threads = atoi (optarg);
diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
index 7b5e67a09bd2..9a65877f30c3 100644
--- a/utils/nfsd/nfsd.c
+++ b/utils/nfsd/nfsd.c
@@ -27,6 +27,7 @@
 #include "nfslib.h"
 #include "nfssvc.h"
 #include "xlog.h"
+#include "xcommon.h"
 
 #ifndef NFSD_NPROC
 #define NFSD_NPROC 8
@@ -67,23 +68,9 @@ main(int argc, char **argv)
 	int grace = -1;
 	int lease = -1;
 
-	progname = strdup(basename(argv[0]));
-	if (!progname) {
-		fprintf(stderr, "%s: unable to allocate memory.\n", argv[0]);
-		exit(1);
-	}
-
-	port = strdup("nfs");
-	if (!port) {
-		fprintf(stderr, "%s: unable to allocate memory.\n", progname);
-		exit(1);
-	}
-
-	haddr = malloc(sizeof(char *));
-	if (!haddr) {
-		fprintf(stderr, "%s: unable to allocate memory.\n", progname);
-		exit(1);
-	}
+	progname = xstrdup(basename(argv[0]));
+	port = xstrdup("nfs");
+	haddr = xmalloc(sizeof(char *));
 	haddr[0] = NULL;
 
 	xlog_syslog(0);
@@ -103,12 +90,7 @@ main(int argc, char **argv)
 					exit(1);
 				}
 			}
-			haddr[hcounter] = strdup(optarg);
-			if (!haddr[hcounter]) {
-				fprintf(stderr, "%s: unable to allocate "
-					"memory.\n", progname);
-				exit(1);
-			}
+			haddr[hcounter] = xstrdup(optarg);
 			hcounter++;
 			break;
 		case 'P':	/* XXX for nfs-server compatibility */
@@ -121,12 +103,7 @@ main(int argc, char **argv)
 				usage(progname);
 			}
 			free(port);
-			port = strdup(optarg);
-			if (!port) {
-				fprintf(stderr, "%s: unable to allocate "
-						"memory.\n", progname);
-				exit(1);
-			}
+			port = xstrdup(optarg);
 			break;
 		case 'r':
 			rdma_port = "nfsrdma";
diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c
index 63545fc09143..a027343a078d 100644
--- a/utils/nfsidmap/nfsidmap.c
+++ b/utils/nfsidmap/nfsidmap.c
@@ -441,11 +441,7 @@ int main(int argc, char **argv)
 
 	key = strtol(argv[optind++], NULL, 10);
 
-	arg = strdup(argv[optind]);
-	if (arg == NULL) {
-		xlog_err("strdup failed: %m");
-		return EXIT_FAILURE;
-	}
+	arg = xstrdup(argv[optind]);
 	type = strtok(arg, ":");
 	value = strtok(NULL, ":");
 	if (value == NULL) {
diff --git a/utils/statd/statd.c b/utils/statd/statd.c
index e5b4c980a86b..15f2b18d104d 100644
--- a/utils/statd/statd.c
+++ b/utils/statd/statd.c
@@ -332,11 +332,8 @@ int main (int argc, char **argv)
 				exit(1);
 			break;
 		case 'H': /* PRC: specify the ha-callout program */
-			if ((ha_callout_prog = xstrdup(optarg)) == NULL) {
-				fprintf(stderr, "%s: xstrdup(%s) failed!\n",
-					argv[0], optarg);
+			if ((ha_callout_prog = xstrdup(optarg)) == NULL)
 				exit(1);
-			}
 			break;
 		case '?':	/* heeeeeelllllllpppp? heh */
 		case 'h':
-- 
2.10.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2016-12-02  3:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02  1:09 [PATCH 0/4] 4 assorted nfs-utils patches NeilBrown
2016-12-02  1:09 ` [PATCH 1/4] mount: don't hide temporary error code on timeout NeilBrown
2016-12-02  1:09 ` [PATCH 3/4] Remove all use of the nfsctl system call NeilBrown
2016-12-02  1:09 ` [PATCH 4/4] Remove error messages on xstrdup failure NeilBrown
2016-12-02  3:26   ` NeilBrown [this message]
2016-12-02  1:09 ` [PATCH 2/4] mount: take history into account when assessing if an error is permanent NeilBrown
2016-12-06 16:30 ` [PATCH 0/4] 4 assorted nfs-utils patches 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=878trz6mf3.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=SteveD@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.