Skip to contentSkip to conversation

PATCH: Respect /etc/services

PATCH H. J. Lu 1 participant 1 message Sep 12, 2002

Subsystems (2)
lore
Share & tools
lore

H. J. Lu

author
#0 lore raw

FYI, I am going to check in this patch shortly.

H.J.
----
Index: configure.in
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/configure.in,v
retrieving revision 1.30

configure.in +2 -0
diff -u -p -r1.30 configure.in
@@ -98,6 +98,8 @@ dnl ************************************
 dnl Check for functions
 dnl *************************************************************
 AC_HAVE_FUNCS(innetgr)
+AC_HAVE_FUNCS(svctcp_socket)
+AC_HAVE_FUNCS(svcudp_socket)
 
 dnl *************************************************************
 dnl Export some path names to config.h

Index: support/include/config.h.in
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/support/include/config.h.in,v retrieving revision 1.1.1.1

include/config.h.in +8 -0
diff -u -p -r1.1.1.1 config.h.in
@@ -9,6 +9,14 @@
  */
 #undef  HAVE_INNETGR
 
+/* Define this if you have svctcp_socket
+ */
+#undef  HAVE_SVCTCP_SOCKET
+
+/* Define this if you have svcudp_socket
+ */
+#undef  HAVE_SVCUDP_SOCKET
+
 /* Define this if you want NFSv3 support compiled in
  */
 #undef  NFS3_SUPPORTED

Index: support/include/nfslib.h
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/support/include/nfslib.h,v retrieving revision 1.6

include/nfslib.h +3 -0
diff -u -p -r1.6 nfslib.h
@@ -125,4 +125,7 @@ struct nfs_fh_len *	getfh_size(struct so
 /* lockd. */
 int			lockdsvc();
 
+extern			int svctcp_socket (u_long __number, int __reuse);
+extern			int svcudp_socket (u_long __number, int __reuse);
+
 #endif /* NFSLIB_H */

Index: support/nfs/Makefile
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/support/nfs/Makefile,v retrieving revision 1.1.1.1

nfs/Makefile +2 -1
diff -u -p -r1.1.1.1 Makefile
@@ -5,7 +5,8 @@
 LIBNAME	= libnfs.a
 OBJS	= exports.o rmtab.o xio.o \
 	  rpcmisc.o rpcdispatch.o xlog.o xmalloc.o wildmat.o \
-	  nfssvc.o nfsclient.o nfsexport.o getfh.o nfsctl.o lockdsvc.o
+	  nfssvc.o nfsclient.o nfsexport.o getfh.o nfsctl.o \
+	  lockdsvc.o svc_socket.o
 
 include $(TOP)rules.mk
 

Index: support/nfs/rpcmisc.c
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/support/nfs/rpcmisc.c,v retrieving revision 1.11

nfs/rpcmisc.c +10 -2
diff -u -p -r1.11 rpcmisc.c
@@ -73,11 +73,15 @@ rpc_init(char *name, int prog, int vers,
 				transp = last_transp;
 				goto udp_transport;
 			}
-			if ((sock = makesock(defport, IPPROTO_UDP)) < 0) {
+			if (defport == 0)
+				sock = RPC_ANYSOCK;
+			else if ((sock = makesock(defport, IPPROTO_UDP)) < 0) {
 				xlog(L_FATAL, "%s: cannot make a UDP socket\n",
 						name);
 			}
 		}
+		if (sock == RPC_ANYSOCK)
+			sock = svcudp_socket (prog, 1);
 		transp = svcudp_create(sock);
 		if (transp == NULL) {
 			xlog(L_FATAL, "cannot create udp service.");
@@ -99,11 +103,15 @@ rpc_init(char *name, int prog, int vers,
 				transp = last_transp;
 				goto tcp_transport;
 			}
-			if ((sock = makesock(defport, IPPROTO_TCP)) < 0) {
+			if (defport == 0)
+				sock = RPC_ANYSOCK;
+			else if ((sock = makesock(defport, IPPROTO_TCP)) < 0) {
 				xlog(L_FATAL, "%s: cannot make a TCP socket\n",
 						name);
 			}
 		}
+		if (sock == RPC_ANYSOCK)
+			sock = svctcp_socket (prog, 1);
 		transp = svctcp_create(sock, 0, 0);
 		if (transp == NULL) {
 			xlog(L_FATAL, "cannot create tcp service.");

Index: utils/nfsd/nfsd.c
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/utils/nfsd/nfsd.c,v retrieving revision 1.3

nfsd/nfsd.c +7 -3
diff -u -p -r1.3 nfsd.c
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <getopt.h>
 #include <syslog.h>
+#include <netdb.h>
 #include "nfslib.h"
 
 static void	usage(const char *);
@@ -25,10 +26,13 @@ int
 main(int argc, char **argv)
 {
 	int	count = 1, c, error, port, fd;
+	struct servent *ent;
 
-	port = 2049;
-
-	/* FIXME: Check for nfs in /etc/services */
+	ent = getservbyname ("nfs", "udp");
+	if (ent != NULL)
+		port = ntohs (ent->s_port);
+	else
+		port = 2049;
 
 	while ((c = getopt(argc, argv, "hp:P:")) != EOF) {
 		switch(c) {

Index: utils/rquotad/rquota_svc.c
===================================================================
RCS file: /cvsroot/nfs/nfs-utils/utils/rquotad/rquota_svc.c,v retrieving revision 1.7

rquotad/rquota_svc.c +20 -2
diff -u -p -r1.7 rquota_svc.c
@@ -38,6 +38,7 @@
 #include <signal.h>
 #include <getopt.h>
 #include <rpcmisc.h>
+#include <nfslib.h>
 
 #ifdef __STDC__
 #define SIG_PF void(*)(int)
@@ -222,11 +223,20 @@ usage(const char *prog, int n)
   exit(n);
 }
 
+static void
+killer (int sig)
+{
+   (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
+   (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
+   syslog(LOG_ERR, "caught signal %d, un-registering and exiting.", sig);
+}
+
 int main(int argc, char **argv)
 {
    register SVCXPRT *transp;
    char c;
    int port = 0;
+   struct sigaction sa;
 
    (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
    (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
@@ -263,12 +273,20 @@ int main(int argc, char **argv)
    }
 
    /* WARNING: the following works on Linux and SysV, but not BSD! */
-   signal(SIGCHLD, SIG_IGN);
+   sa.sa_handler = SIG_IGN;
+   sa.sa_flags = 0;
+   sigemptyset(&sa.sa_mask);
+   sigaction(SIGCHLD, &sa, NULL);
+
+   sa.sa_handler = killer;
+   sigaction(SIGHUP, &sa, NULL);
+   sigaction(SIGINT, &sa, NULL);
+   sigaction(SIGTERM, &sa, NULL);
 
    if (port)
      transp = svcudp_create(makesock(port, IPPROTO_UDP));
    else
-     transp = svcudp_create(RPC_ANYSOCK);
+     transp = svcudp_create(svcudp_socket (RQUOTAPROG, 1));
    if (transp == NULL) {
       syslog(LOG_ERR, "cannot create udp service.");
       exit(1);
nfs/svc_socket.c new file +187 -0

187 lines not on this page · raw message

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs