about summary refs log tree commit diff
path: root/sunrpc
diff options
context:
space:
mode:
Diffstat (limited to 'sunrpc')
-rw-r--r--sunrpc/Makefile2
-rw-r--r--sunrpc/clnt_tcp.c6
-rw-r--r--sunrpc/clnt_udp.c16
-rw-r--r--sunrpc/clnt_unix.c6
-rw-r--r--sunrpc/create_xid.c53
-rw-r--r--sunrpc/pmap_rmt.c11
-rw-r--r--sunrpc/svc_tcp.c105
-rw-r--r--sunrpc/svc_unix.c54
8 files changed, 120 insertions, 133 deletions
diff --git a/sunrpc/Makefile b/sunrpc/Makefile
index 2a6614c977..0a327ea4f7 100644
--- a/sunrpc/Makefile
+++ b/sunrpc/Makefile
@@ -67,7 +67,7 @@ routines := auth_none auth_unix authuxprot bindrsvprt \
 	    xdr_rec xdr_ref xdr_stdio publickey xdr_sizeof \
 	    auth_des authdes_prot des_crypt des_impl des_soft \
 	    key_call key_prot netname openchild rtime svcauth_des xcrypt\
-	    clnt_unix svc_unix
+	    clnt_unix svc_unix create_xid
 
 others := rpcinfo
 install-bin := rpcgen
diff --git a/sunrpc/clnt_tcp.c b/sunrpc/clnt_tcp.c
index 07224e313b..abb284982e 100644
--- a/sunrpc/clnt_tcp.c
+++ b/sunrpc/clnt_tcp.c
@@ -59,6 +59,8 @@ static char sccsid[] = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
 #include <sys/socket.h>
 #include <rpc/pmap_clnt.h>
 
+extern u_long _create_xid (void);
+
 #define MCALL_MSG_SIZE 24
 
 struct ct_data
@@ -115,7 +117,6 @@ clnttcp_create (struct sockaddr_in *raddr, u_long prog, u_long vers,
 {
   CLIENT *h;
   struct ct_data *ct = (struct ct_data *) mem_alloc (sizeof (*ct));
-  struct timeval now;
   struct rpc_msg call_msg;
 
   h = (CLIENT *) mem_alloc (sizeof (*h));
@@ -185,8 +186,7 @@ clnttcp_create (struct sockaddr_in *raddr, u_long prog, u_long vers,
   /*
    * Initialize call message
    */
-  (void) __gettimeofday (&now, (struct timezone *) 0);
-  call_msg.rm_xid = __getpid () ^ now.tv_sec ^ now.tv_usec;
+  call_msg.rm_xid = _create_xid ();
   call_msg.rm_direction = CALL;
   call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
   call_msg.rm_call.cb_prog = prog;
diff --git a/sunrpc/clnt_udp.c b/sunrpc/clnt_udp.c
index 0842e5ac1a..ec63f60f8e 100644
--- a/sunrpc/clnt_udp.c
+++ b/sunrpc/clnt_udp.c
@@ -50,6 +50,7 @@ static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
 #include <rpc/pmap_clnt.h>
 
 extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);
+extern u_long _create_xid (void);
 
 /*
  * UDP bases client side rpc operations
@@ -109,18 +110,12 @@ struct cu_data
  * sent and received.
  */
 CLIENT *
-clntudp_bufcreate (raddr, program, version, wait, sockp, sendsz, recvsz)
-     struct sockaddr_in *raddr;
-     u_long program;
-     u_long version;
-     struct timeval wait;
-     int *sockp;
-     u_int sendsz;
-     u_int recvsz;
+clntudp_bufcreate (struct sockaddr_in *raddr, u_long program, u_long version,
+		   struct timeval wait, int *sockp, u_int sendsz,
+		   u_int recvsz)
 {
   CLIENT *cl;
   struct cu_data *cu = NULL;
-  struct timeval now;
   struct rpc_msg call_msg;
 
   cl = (CLIENT *) mem_alloc (sizeof (CLIENT));
@@ -143,7 +138,6 @@ clntudp_bufcreate (raddr, program, version, wait, sockp, sendsz, recvsz)
     }
   cu->cu_outbuf = &cu->cu_inbuf[recvsz];
 
-  (void) __gettimeofday (&now, (struct timezone *) 0);
   if (raddr->sin_port == 0)
     {
       u_short port;
@@ -163,7 +157,7 @@ clntudp_bufcreate (raddr, program, version, wait, sockp, sendsz, recvsz)
   cu->cu_total.tv_usec = -1;
   cu->cu_sendsz = sendsz;
   cu->cu_recvsz = recvsz;
-  call_msg.rm_xid = __getpid () ^ now.tv_sec ^ now.tv_usec;
+  call_msg.rm_xid = _create_xid ();
   call_msg.rm_direction = CALL;
   call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
   call_msg.rm_call.cb_prog = program;
diff --git a/sunrpc/clnt_unix.c b/sunrpc/clnt_unix.c
index f5d06ce5f5..365bdace3f 100644
--- a/sunrpc/clnt_unix.c
+++ b/sunrpc/clnt_unix.c
@@ -56,6 +56,8 @@
 #include <sys/socket.h>
 #include <rpc/pmap_clnt.h>
 
+extern u_long _create_xid (void);
+
 #define MCALL_MSG_SIZE 24
 
 struct ct_data
@@ -112,7 +114,6 @@ clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
 {
   CLIENT *h;
   struct ct_data *ct = (struct ct_data *) mem_alloc (sizeof (*ct));
-  struct timeval now;
   struct rpc_msg call_msg;
   int len;
 
@@ -167,8 +168,7 @@ clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
   /*
    * Initialize call message
    */
-  __gettimeofday (&now, (struct timezone *) 0);
-  call_msg.rm_xid = __getpid () ^ now.tv_sec ^ now.tv_usec;
+  call_msg.rm_xid = _create_xid ();
   call_msg.rm_direction = CALL;
   call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
   call_msg.rm_call.cb_prog = prog;
diff --git a/sunrpc/create_xid.c b/sunrpc/create_xid.c
new file mode 100644
index 0000000000..15fb367bca
--- /dev/null
+++ b/sunrpc/create_xid.c
@@ -0,0 +1,53 @@
+/* Copyright (c) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA. */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <bits/libc-lock.h>
+
+/* The RPC code is not threadsafe, but new code should be threadsafe. */
+
+__libc_lock_define_initialized (static, createxid_lock)
+
+static int is_initialized;
+static struct drand48_data __rpc_lrand48_data;
+
+unsigned long
+_create_xid (void)
+{
+  unsigned long res;
+
+  __libc_lock_lock (createxid_lock);
+
+  if (!is_initialized)
+    {
+      struct timeval now;
+
+      __gettimeofday (&now, (struct timezone *) 0);
+      srand48_r (now.tv_sec ^ now.tv_usec, &__rpc_lrand48_data);
+      is_initialized = 1;
+    }
+
+  lrand48_r (&__rpc_lrand48_data, &res);
+
+  __libc_lock_unlock (createxid_lock);
+
+  return res;
+}
diff --git a/sunrpc/pmap_rmt.c b/sunrpc/pmap_rmt.c
index ced817d809..e0f52c9145 100644
--- a/sunrpc/pmap_rmt.c
+++ b/sunrpc/pmap_rmt.c
@@ -56,6 +56,8 @@ static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
 #include <arpa/inet.h>
 #define MAX_BROADCAST_SIZE 1400
 
+extern u_long _create_xid (void);
+
 static struct timeval timeout = {3, 0};
 
 /*
@@ -112,9 +114,7 @@ pmap_rmtcall (addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_p
  * written for XDR_ENCODE direction only
  */
 bool_t
-xdr_rmtcall_args (xdrs, cap)
-     XDR *xdrs;
-     struct rmtcallargs *cap;
+xdr_rmtcall_args (XDR *xdrs, struct rmtcallargs *cap)
 {
   u_int lenposition, argposition, position;
 
@@ -237,6 +237,7 @@ clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
   AUTH *unix_auth = authunix_create_default ();
   XDR xdr_stream;
   XDR *xdrs = &xdr_stream;
+  struct timeval t;
   int outlen, inlen, nets;
   socklen_t fromlen;
   int sock;
@@ -252,7 +253,6 @@ clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
   struct rmtcallargs a;
   struct rmtcallres r;
   struct rpc_msg msg;
-  struct timeval t;
   char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
 
   /*
@@ -281,8 +281,7 @@ clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
   baddr.sin_port = htons (PMAPPORT);
   baddr.sin_addr.s_addr = htonl (INADDR_ANY);
 /*      baddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY); */
-  (void) __gettimeofday (&t, (struct timezone *) 0);
-  msg.rm_xid = xid = __getpid () ^ t.tv_sec ^ t.tv_usec;
+  msg.rm_xid = xid = _create_xid ();
   t.tv_usec = 0;
   msg.rm_direction = CALL;
   msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
diff --git a/sunrpc/svc_tcp.c b/sunrpc/svc_tcp.c
index 0c2ce9650a..cd5cecf0f7 100644
--- a/sunrpc/svc_tcp.c
+++ b/sunrpc/svc_tcp.c
@@ -46,6 +46,7 @@ static char sccsid[] = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
 #include <string.h>
 #include <rpc/rpc.h>
 #include <sys/socket.h>
+#include <sys/poll.h>
 #include <errno.h>
 #include <stdlib.h>
 
@@ -284,66 +285,42 @@ svctcp_destroy (SVCXPRT *xprt)
   mem_free ((caddr_t) xprt, sizeof (SVCXPRT));
 }
 
-/*
- * All read operations timeout after 35 seconds.
- * A timeout is fatal for the connection.
- */
-static struct timeval wait_per_try = {35, 0};
 
 /*
  * reads data from the tcp connection.
  * any error is fatal and the connection is closed.
  * (And a read of zero bytes is a half closed stream => error.)
- *
- * Note: we have to be careful here not to allow ourselves to become
- * blocked too long in this routine.  While we're waiting for data from one
- * client, another client may be trying to connect.  To avoid this situation,
- * some code from svc_run() is transplanted here: the select() loop checks
- * all RPC descriptors including the one we want and calls svc_getreqset2()
- * to handle new requests if any are detected.
  */
 static int
 readtcp (char *xprtptr, char *buf, int len)
 {
   SVCXPRT *xprt = (SVCXPRT *)xprtptr;
   int sock = xprt->xp_sock;
-#ifdef FD_SETSIZE
-  fd_set readfds;
-#else
-  int mask = 1 << sock;
-  int readfds;
-#endif /* def FD_SETSIZE */
-  while (1)
+  int milliseconds = 35 * 1000;
+  struct pollfd pollfd;
+
+  do
     {
-      struct timeval timeout = wait_per_try;
-      readfds = svc_fdset;
-#ifdef FD_SETSIZE
-      FD_SET (sock, &readfds);
-#else
-      readfds |= (1 << sock);
-#endif /* def FD_SETSIZE */
-      if (__select (_rpc_dtablesize (), &readfds, (fd_set *) NULL,
-		    (fd_set *) NULL, &timeout) <= 0)
+      pollfd.fd = sock;
+      pollfd.events = POLLIN;
+      switch (__poll (&pollfd, 1, milliseconds))
 	{
+	case -1:
 	  if (errno == EINTR)
 	    continue;
+	  /*FALLTHROUGH*/
+	case 0:
 	  goto fatal_err;
-	}
-
-#ifdef FD_SETSIZE
-      if (FD_ISSET (sock, &readfds))
-#else
-      if (readfds == mask)
-#endif /* def FD_SETSIZE */
-	break;
-
-      svc_getreqset (&readfds);
+	default:
+	  break;
+	  }
     }
+  while ((pollfd.revents & POLLIN) == 0);
 
   if ((len = __read (sock, buf, len)) > 0)
     return len;
 
-fatal_err:
+ fatal_err:
   ((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
   return -1;
 }
@@ -362,12 +339,11 @@ writetcp (char *xprtptr, char * buf, int len)
     {
       if ((i = __write (xprt->xp_sock, buf, cnt)) < 0)
 	{
-	  ((struct tcp_conn *) (xprt->xp_p1))->strm_stat =
-	    XPRT_DIED;
-	  return (-1);
+	  ((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
+	  return -1;
 	}
     }
-  return (len);
+  return len;
 }
 
 static enum xprt_stat
@@ -377,19 +353,16 @@ svctcp_stat (SVCXPRT *xprt)
   (struct tcp_conn *) (xprt->xp_p1);
 
   if (cd->strm_stat == XPRT_DIED)
-    return (XPRT_DIED);
+    return XPRT_DIED;
   if (!xdrrec_eof (&(cd->xdrs)))
-    return (XPRT_MOREREQS);
-  return (XPRT_IDLE);
+    return XPRT_MOREREQS;
+  return XPRT_IDLE;
 }
 
 static bool_t
-svctcp_recv (xprt, msg)
-     SVCXPRT *xprt;
-     struct rpc_msg *msg;
+svctcp_recv (SVCXPRT *xprt, struct rpc_msg *msg)
 {
-  struct tcp_conn *cd =
-  (struct tcp_conn *) (xprt->xp_p1);
+  struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
   XDR *xdrs = &(cd->xdrs);
 
   xdrs->x_op = XDR_DECODE;
@@ -397,42 +370,32 @@ svctcp_recv (xprt, msg)
   if (xdr_callmsg (xdrs, msg))
     {
       cd->x_id = msg->rm_xid;
-      return (TRUE);
+      return TRUE;
     }
   cd->strm_stat = XPRT_DIED;	/* XXXX */
-  return (FALSE);
+  return FALSE;
 }
 
 static bool_t
-svctcp_getargs (xprt, xdr_args, args_ptr)
-     SVCXPRT *xprt;
-     xdrproc_t xdr_args;
-     caddr_t args_ptr;
+svctcp_getargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
 {
-
-  return ((*xdr_args) (&(((struct tcp_conn *) (xprt->xp_p1))->xdrs), args_ptr));
+  return ((*xdr_args) (&(((struct tcp_conn *)
+			  (xprt->xp_p1))->xdrs), args_ptr));
 }
 
 static bool_t
-svctcp_freeargs (xprt, xdr_args, args_ptr)
-     SVCXPRT *xprt;
-     xdrproc_t xdr_args;
-     caddr_t args_ptr;
+svctcp_freeargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
 {
-  XDR *xdrs =
-  &(((struct tcp_conn *) (xprt->xp_p1))->xdrs);
+  XDR *xdrs = &(((struct tcp_conn *) (xprt->xp_p1))->xdrs);
 
   xdrs->x_op = XDR_FREE;
   return ((*xdr_args) (xdrs, args_ptr));
 }
 
 static bool_t
-svctcp_reply (xprt, msg)
-     SVCXPRT *xprt;
-     struct rpc_msg *msg;
+svctcp_reply (SVCXPRT *xprt, struct rpc_msg *msg)
 {
-  struct tcp_conn *cd =
-  (struct tcp_conn *) (xprt->xp_p1);
+  struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
   XDR *xdrs = &(cd->xdrs);
   bool_t stat;
 
@@ -440,5 +403,5 @@ svctcp_reply (xprt, msg)
   msg->rm_xid = cd->x_id;
   stat = xdr_replymsg (xdrs, msg);
   (void) xdrrec_endofrecord (xdrs, TRUE);
-  return (stat);
+  return stat;
 }
diff --git a/sunrpc/svc_unix.c b/sunrpc/svc_unix.c
index 9ee64d0303..4fba428926 100644
--- a/sunrpc/svc_unix.c
+++ b/sunrpc/svc_unix.c
@@ -43,6 +43,7 @@
 #include <rpc/rpc.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
+#include <sys/poll.h>
 #include <errno.h>
 #include <stdlib.h>
 
@@ -352,12 +353,6 @@ __msgwrite (int sock, void *buf, size_t cnt)
 }
 
 /*
- * All read operations timeout after 35 seconds.
- * A timeout is fatal for the connection.
- */
-static struct timeval wait_per_try = {35, 0};
-
-/*
  * reads data from the unix connection.
  * any error is fatal and the connection is closed.
  * (And a read of zero bytes is a half closed stream => error.)
@@ -367,38 +362,26 @@ readunix (char *xprtptr, char *buf, int len)
 {
   SVCXPRT *xprt = (SVCXPRT *) xprtptr;
   int sock = xprt->xp_sock;
-#ifdef FD_SETSIZE
-  fd_set readfds;
-#else
-  int mask = 1 << sock;
-  int readfds;
-#endif /* def FD_SETSIZE */
-  while (1)
+  int milliseconds = 35 * 1000;
+  struct pollfd pollfd;
+
+  do
     {
-      struct timeval timeout = wait_per_try;
-      readfds = svc_fdset;
-#ifdef FD_SETSIZE
-      FD_SET (sock, &readfds);
-#else
-      readfds |= (1 << sock);
-#endif /* def FD_SETSIZE */
-      if (__select (_rpc_dtablesize (), &readfds, (fd_set *) NULL,
-		    (fd_set *) NULL, &timeout) <= 0)
+      pollfd.fd = sock;
+      pollfd.events = POLLIN;
+      switch (__poll (&pollfd, 1, milliseconds))
 	{
+	case -1:
 	  if (errno == EINTR)
 	    continue;
+	  /*FALLTHROUGH*/
+	case 0:
 	  goto fatal_err;
+	default:
+	  break;
 	}
-
-#ifdef FD_SETSIZE
-      if (FD_ISSET (sock, &readfds))
-#else
-      if (readfds == mask)
-#endif /* def FD_SETSIZE */
-	break;
-
-      svc_getreqset (&readfds);
     }
+  while ((pollfd.revents & POLLIN) == 0);
 
   if ((len = __msgread (sock, buf, len)) > 0)
     return len;
@@ -471,10 +454,7 @@ svcunix_getargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
 }
 
 static bool_t
-svcunix_freeargs (xprt, xdr_args, args_ptr)
-     SVCXPRT *xprt;
-     xdrproc_t xdr_args;
-     caddr_t args_ptr;
+svcunix_freeargs (SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr)
 {
   XDR *xdrs = &(((struct unix_conn *) (xprt->xp_p1))->xdrs);
 
@@ -483,9 +463,7 @@ svcunix_freeargs (xprt, xdr_args, args_ptr)
 }
 
 static bool_t
-svcunix_reply (xprt, msg)
-     SVCXPRT *xprt;
-     struct rpc_msg *msg;
+svcunix_reply (SVCXPRT *xprt, struct rpc_msg *msg)
 {
   struct unix_conn *cd = (struct unix_conn *) (xprt->xp_p1);
   XDR *xdrs = &(cd->xdrs);