X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fsvc_socket.c;h=f44217a404821dcd059e8374531d3ac32c12d1fa;hp=d712cabbba387967d21275b546acafa3dc6be3f7;hb=2bb403d1547790e731e5b151f9ef41880a6eb6c7;hpb=3d7e64fd2a1e226a5169c2fde2852bfcca07845f diff --git a/support/nfs/svc_socket.c b/support/nfs/svc_socket.c index d712cab..f44217a 100644 --- a/support/nfs/svc_socket.c +++ b/support/nfs/svc_socket.c @@ -101,8 +101,6 @@ svc_socket (u_long number, int type, int protocol, int reuse) } else { - if (bindresvport (sock, &addr)) - { addr.sin_port = 0; if (bind (sock, (struct sockaddr *) &addr, len) < 0) { @@ -110,14 +108,24 @@ svc_socket (u_long number, int type, int protocol, int reuse) (void) __close (sock); sock = -1; } - } } - if (sock >= 0 && protocol == IPPROTO_TCP) + if (sock >= 0) { - /* Make the TCP rendezvous socket non-block to avoid - * problems with blocking in accept() after a spurious - * wakeup from the kernel */ + /* This socket might be shared among multiple processes + * if mountd is run multi-threaded. So it is safest to + * make it non-blocking, else all threads might wake + * one will get the data, and the others will block + * indefinitely. + * In all cases, transaction on this socket are atomic + * (accept for TCP, packet-read and packet-write for UDP) + * so O_NONBLOCK will not confuse unprepared code causing + * it to corrupt messages. + * It generally safest to have O_NONBLOCK when doing an accept + * as if we get a RST after the SYN and before accept runs, + * we can block despite being told there was an acceptable + * connection. + */ int flags; if ((flags = fcntl(sock, F_GETFL)) < 0) { @@ -151,7 +159,7 @@ svctcp_socket (u_long number, int reuse) int svcudp_socket (u_long number, int reuse) { - return svc_socket (number, SOCK_DGRAM, IPPROTO_UDP, reuse); + return svc_socket (number, SOCK_DGRAM, IPPROTO_UDP, 0); } #ifdef TEST