]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/svc_socket.c
Merge branch 'upstream'
[nfs-utils.git] / support / nfs / svc_socket.c
index a3cb7ce2e1751dddedaf7e28ba63d4a8cf4d36c7..c41a1a3b15f7154f7c497e121516e6d4487bdbf8 100644 (file)
@@ -22,6 +22,7 @@
 #include <netdb.h>
 #include <rpc/rpc.h>
 #include <sys/socket.h>
+#include <sys/fcntl.h>
 #include <errno.h>
 
 #ifdef _LIBC
@@ -41,7 +42,7 @@ svc_socket (u_long number, int type, int protocol, int reuse)
   socklen_t len = sizeof (struct sockaddr_in);
   char rpcdata [1024], servdata [1024];
   struct rpcent rpcbuf, *rpcp;
-  struct servent servbuf, *servp;
+  struct servent servbuf, *servp = NULL;
   int sock, ret;
   const char *proto = protocol == IPPROTO_TCP ? "tcp" : "udp";
 
@@ -112,6 +113,26 @@ svc_socket (u_long number, int type, int protocol, int reuse)
        }
     }
 
+  if (sock >= 0 && protocol == IPPROTO_TCP)
+    {
+       /* Make the TCP rendezvous socket non-block to avoid
+        * problems with blocking in accept() after a spurious
+        * wakeup from the kernel */
+       int flags;
+       if ((flags = fcntl(sock, F_GETFL)) < 0)
+         {
+             perror (_("svc_socket: can't get socket flags"));
+             (void) __close (sock);
+             sock = -1;
+         }
+       else if (fcntl(sock, F_SETFL, flags|O_NONBLOCK) < 0)
+         {
+             perror (_("svc_socket: can't set socket flags"));
+             (void) __close (sock);
+             sock = -1;
+         }
+    }
+
   return sock;
 }