]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/nfssvc.c
"rpc.nfsd XX" should not fail if ports are already open.
[nfs-utils.git] / support / nfs / nfssvc.c
index a6ea410226f193d5f22def299ff9d9a57914682a..ef7d8e1109cbb616a8b37e825f852ad191f2fed4 100644 (file)
 static void
 nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
 {
-       int fd, on=1;
+       int fd, n, on=1;
        char buf[BUFSIZ];
        int udpfd = -1, tcpfd = -1;
        struct sockaddr_in sin;
 
+       fd = open(NFSD_PORTS_FILE, O_RDONLY);
+       if (fd < 0)
+               return;
+       n = read(fd, buf, BUFSIZ);
+       close(fd);
+       if (n != 0)
+               return;
+       /* there are no ports currently open, so it is safe to
+        * try to open some and pass them through.
+        * Note: If the user explicitly asked for 'udp', then
+        * we should probably check if that is open, and should
+        * open it if not.  However we don't yet.  All sockets
+        * have to be opened when the first daemon is started.
+        */
        fd = open(NFSD_PORTS_FILE, O_WRONLY);
        if (fd < 0)
                return;
@@ -135,9 +149,12 @@ nfssvc(int port, int nrservs, unsigned int versbits, unsigned protobits,
        struct nfsctl_arg       arg;
        int fd;
 
-       nfssvc_setfds(port, protobits, haddr);
-
+       /* Note: must set versions before fds so that
+        * the ports get registered with portmap against correct
+        * versions
+        */
        nfssvc_versbits(versbits);
+       nfssvc_setfds(port, protobits, haddr);
 
        fd = open(NFSD_THREAD_FILE, O_WRONLY);
        if (fd < 0)