X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=support%2Fnfs%2Fnfssvc.c;h=33c15a7acbdaf113daf1a47cd7952ccd5eaf62cd;hb=aa633adcbe63b7539d23d7e0fb1342659cf22953;hp=1feffdde3283f57c53bb1ab3f34b8dcd92154fd1;hpb=b0c3cbfee702c019dab0a22557bbf38e24dfcee1;p=nfs-utils.git diff --git a/support/nfs/nfssvc.c b/support/nfs/nfssvc.c index 1feffdd..33c15a7 100644 --- a/support/nfs/nfssvc.c +++ b/support/nfs/nfssvc.c @@ -28,11 +28,25 @@ 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)); } } @@ -102,7 +116,7 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr) return; } static void -nfssvc_versbits(unsigned int ctlbits) +nfssvc_versbits(unsigned int ctlbits, int minorvers4) { int fd, n, off; char buf[BUFSIZ], *ptr; @@ -119,6 +133,11 @@ nfssvc_versbits(unsigned int ctlbits) else off += snprintf(ptr+off, BUFSIZ - off, "-%d ", n); } + n = minorvers4 >= 0 ? minorvers4 : -minorvers4; + if (n >= NFSD_MINMINORVERS4 && n <= NFSD_MAXMINORVERS4) + off += snprintf(ptr+off, BUFSIZ - off, "%c4.%d", + minorvers4 > 0 ? '+' : '-', + n); snprintf(ptr+off, BUFSIZ - off, "\n"); if (write(fd, buf, strlen(buf)) != strlen(buf)) { syslog(LOG_ERR, "nfssvc: Setting version failed: errno %d (%s)", @@ -129,8 +148,8 @@ nfssvc_versbits(unsigned int ctlbits) return; } int -nfssvc(int port, int nrservs, unsigned int versbits, unsigned protobits, - char *haddr) +nfssvc(int port, int nrservs, unsigned int versbits, int minorvers4, + unsigned protobits, char *haddr) { struct nfsctl_arg arg; int fd; @@ -139,7 +158,7 @@ nfssvc(int port, int nrservs, unsigned int versbits, unsigned protobits, * the ports get registered with portmap against correct * versions */ - nfssvc_versbits(versbits); + nfssvc_versbits(versbits, minorvers4); nfssvc_setfds(port, protobits, haddr); fd = open(NFSD_THREAD_FILE, O_WRONLY);