Skip to contentSkip to conversation

Two missing clean ups for nfs-utils

PATCH In review Chuck Lever 2 participants 4 messages Oct 2, 2008 – Oct 8, 2008 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Two missing clean ups for nfs-utils

Hi Steve-

The following two clean-up patches are not included in your nfs-utils git repo, but were sent in my September 5 patch set for nfs-utils.

For reference, these were patches 13/19 and 14/19 in that series.

---

Chuck Lever (2):
nfs-utils: make makesock() static
nfs-utils: Clean up support/nfs/rpcmisc.c:closedown()

 support/nfs/rpcmisc.c |  130 +++++++++++++++++++++++++------------------------
 1 files changed, 65 insertions(+), 65 deletions(-)
Signature · 1 line
Chuck Lever

A message that is not in the archive (sent off-list or not yet received): 20081002154752.25618.18842.stgit-meopP2rzCrTwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org

#2 lore raw

PATCH 1/2 nfs-utils: Clean up support/nfs/rpcmisc.c:closedown()

Clean up: update closedown()'s synopsis to modern C style, and move the function so we can remove the forward declaration.

---

 support/nfs/rpcmisc.c |   48 +++++++++++++++++++++++++-----------------------
 1 files changed, 25 insertions(+), 23 deletions(-)
support/nfs/rpcmisc.c +25 -23
index aa23601..dab2be8 100644
@@ -37,7 +37,6 @@
 #define socklen_t int
 #endif
 
-static void	closedown(int sig);
 static int	makesock(int port, int proto);
 
 #define _RPCSVC_CLOSEDOWN	120
@@ -45,6 +44,31 @@ int	_rpcpmstart = 0;
 int	_rpcfdtype = 0;
 int	_rpcsvcdirty = 0;
 
+static void
+closedown(int sig)
+{
+	(void) signal(sig, closedown);
+
+	if (_rpcsvcdirty == 0) {
+		static int size;
+		int i, openfd;
+
+		if (_rpcfdtype == SOCK_DGRAM)
+			exit(0);
+
+		if (size == 0)
+			size = getdtablesize();
+
+		for (i = 0, openfd = 0; i < size && openfd < 2; i++)
+			if (FD_ISSET(i, &svc_fdset))
+				openfd++;
+		if (openfd <= 1)
+			exit(0);
+	}
+
+	(void) alarm(_RPCSVC_CLOSEDOWN);
+}
+
 void
 rpc_init(char *name, int prog, int vers,
 	 void (*dispatch)(struct svc_req *, register SVCXPRT *),
@@ -139,28 +163,6 @@ rpc_init(char *name, int prog, int vers,
 	}
 }
 
-static void closedown(sig)
-int sig;
-{
-	(void) signal(sig, closedown);
-	if (_rpcsvcdirty == 0) {
-		static int size;
-		int i, openfd;
-
-		if (_rpcfdtype == SOCK_DGRAM)
-			exit(0);
-		if (size == 0) {
-			size = getdtablesize();
-		}
-		for (i = 0, openfd = 0; i < size && openfd < 2; i++)
-			if (FD_ISSET(i, &svc_fdset))
-				openfd++;
-		if (openfd <= 1)
-			exit(0);
-	}
-	(void) alarm(_RPCSVC_CLOSEDOWN);
-}
-
 /*
  * Create listener socket for a given port
  *

A message that is not in the archive (sent off-list or not yet received): 20081002155412.25618.89699.stgit-meopP2rzCrTwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org

#4 lore raw

Re: [PATCH 1/2] nfs-utils: Clean up support/nfs/rpcmisc.c:closedown()

Quoted 5 lines · Chuck Lever

Clean up: update closedown()'s synopsis to modern C style, and move the function so we can remove the forward declaration.

---

Committed.

#5 lore raw

PATCH 2/2 nfs-utils: make makesock() static

In reply to a message not in the archive

Clean up: The makesock() function can become static since it is only used in rpcmisc.c, where it is defined. Fix some minor nits while we're in the area:

o Move it so we can remove it's forward declaration.

o Get rid of unneeded newlines in the xlog() format strings.

o Use htonl(INADDR_ANY) instead of INADDR_ANY to initialize sin_addr. Should make no run-time difference, but is slightly more proper, as the standard definition of INADDR_ANY is in host byte-order.

o Remove the parentheses in the "return" statements.

---

 support/nfs/rpcmisc.c |   82 ++++++++++++++++++++++++-------------------------
 1 files changed, 40 insertions(+), 42 deletions(-)
support/nfs/rpcmisc.c +40 -42
index dab2be8..a0854e7 100644
@@ -37,8 +37,6 @@
 #define socklen_t int
 #endif
 
-static int	makesock(int port, int proto);
-
 #define _RPCSVC_CLOSEDOWN	120
 int	_rpcpmstart = 0;
 int	_rpcfdtype = 0;
@@ -69,6 +67,46 @@ closedown(int sig)
 	(void) alarm(_RPCSVC_CLOSEDOWN);
 }
 
+/*
+ * Create listener socket for a given port
+ *
+ * Return an open network socket on success; otherwise return -1
+ * if some error occurs.
+ */
+static int
+makesock(int port, int proto)
+{
+	struct sockaddr_in sin;
+	int	sock, sock_type, val;
+
+	sock_type = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
+	sock = socket(AF_INET, sock_type, proto);
+	if (sock < 0) {
+		xlog(L_FATAL, "Could not make a socket: %s",
+					strerror(errno));
+		return -1;
+	}
+	memset((char *) &sin, 0, sizeof(sin));
+	sin.sin_family = AF_INET;
+	sin.sin_addr.s_addr = htonl(INADDR_ANY);
+	sin.sin_port = htons(port);
+
+	val = 1;
+	if (proto == IPPROTO_TCP)
+		if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+			       &val, sizeof(val)) < 0)
+			xlog(L_ERROR, "setsockopt failed: %s",
+			     strerror(errno));
+
+	if (bind(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
+		xlog(L_FATAL, "Could not bind name to socket: %s",
+					strerror(errno));
+		return -1;
+	}
+
+	return sock;
+}
+
 void
 rpc_init(char *name, int prog, int vers,
 	 void (*dispatch)(struct svc_req *, register SVCXPRT *),
@@ -162,43 +200,3 @@ rpc_init(char *name, int prog, int vers,
 		alarm(_RPCSVC_CLOSEDOWN);
 	}
 }
-
-/*
- * Create listener socket for a given port
- *
- * Return an open network socket on success; otherwise return -1
- * if some error occurs.
- */
-static int
-makesock(int port, int proto)
-{
-	struct sockaddr_in sin;
-	int	sock, sock_type, val;
-
-	sock_type = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
-	sock = socket(AF_INET, sock_type, proto);
-	if (sock < 0) {
-		xlog(L_FATAL, "Could not make a socket: %s",
-					strerror(errno));
-		return -1;
-	}
-	memset((char *) &sin, 0, sizeof(sin));
-	sin.sin_family = AF_INET;
-	sin.sin_addr.s_addr = htonl(INADDR_ANY);
-	sin.sin_port = htons(port);
-
-	val = 1;
-	if (proto == IPPROTO_TCP)
-		if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-			       &val, sizeof(val)) < 0)
-			xlog(L_ERROR, "setsockopt failed: %s",
-			     strerror(errno));
-
-	if (bind(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
-		xlog(L_FATAL, "Could not bind name to socket: %s",
-					strerror(errno));
-		return -1;
-	}
-
- 	return sock;
-}