]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/nfssvc.c
rpc.mountd: make exportent->e_hostname a dynamically-allocated string
[nfs-utils.git] / support / nfs / nfssvc.c
index 1feffdde3283f57c53bb1ab3f34b8dcd92154fd1..9bbc9a5195d4ad4012bcd626977d321aa1c94c03 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;
@@ -81,7 +95,7 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
                snprintf(buf, BUFSIZ,"%d\n", udpfd); 
                if (write(fd, buf, strlen(buf)) != strlen(buf)) {
                        syslog(LOG_ERR, 
-                              "nfssvc: writting fds to kernel failed: errno %d (%s)", 
+                              "nfssvc: writing fds to kernel failed: errno %d (%s)", 
                               errno, strerror(errno));
                }
                close(fd);
@@ -93,7 +107,7 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
                snprintf(buf, BUFSIZ,"%d\n", tcpfd); 
                if (write(fd, buf, strlen(buf)) != strlen(buf)) {
                        syslog(LOG_ERR, 
-                              "nfssvc: writting fds to kernel failed: errno %d (%s)", 
+                              "nfssvc: writing fds to kernel failed: errno %d (%s)", 
                               errno, strerror(errno));
                }
        }