The more I think about this..... if we want to continue the select() NULL functionality then timeout should be a negative value for poll(), as NULL is unrecognized and zero is a zero-length timeout.

On 04/24/14 18:08, Peter Malone wrote:
As promised. I cleaned up some of the code as well.

One item of note - select() took a NULL value for timeout. I did not want to do 
this with poll(), so I defaulted with 10 instead. We should probably discuss 
this. I didn't even try to compile poll() with NULL - I don't think it's a good 
idea and I'm sure the compiler wouldn't be happy. Thoughts?


Index: nfsd.c
===================================================================
RCS file: /cvs/src/sbin/nfsd/nfsd.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 nfsd.c
--- nfsd.c      11 Mar 2013 17:40:10 -0000      1.32
+++ nfsd.c      24 Apr 2014 22:00:20 -0000
@@ -103,13 +103,10 @@ main(int argc, char *argv[])
  {
        struct nfsd_args nfsdargs;
        struct sockaddr_in inetaddr, inetpeer;
-       fd_set *ready, *sockbits;
-       size_t fd_size;
-       int ch, connect_type_cnt, i, maxsock = 0, msgsock;
+       int ch, connect_type_cnt, i;
        int nfsdcnt = DEFNFSDCNT, on, reregister = 0, sock;
        int udpflag = 0, tcpflag = 0, tcpsock;
        const char *errstr = NULL;
-       socklen_t len;
/* Start by writing to both console and log. */
        openlog("nfsd", LOG_PID | LOG_PERROR, LOG_DAEMON);
@@ -264,7 +261,6 @@ main(int argc, char *argv[])
                        syslog(LOG_ERR, "can't register tcp with portmap");
                        return (1);
                }
-               maxsock = tcpsock;
                connect_type_cnt++;
        }
@@ -274,33 +270,29 @@ main(int argc, char *argv[])
        setproctitle("master");
/*
-        * Allocate space for the fd_set pointers and fill in sockbits
-        */
-       fd_size = howmany(maxsock + 1, NFDBITS) * sizeof(fd_mask);
-       sockbits = malloc(fd_size);
-       ready = malloc(fd_size);
-       if (sockbits == NULL || ready == NULL) {
-               syslog(LOG_ERR, "cannot allocate memory");
-               return (1);
-       }
-       memset(sockbits, 0, fd_size);
-       if (tcpflag)
-               FD_SET(tcpsock, sockbits);
-
-       /*
         * Loop forever accepting connections and passing the sockets
         * into the kernel for the mounts.
         */
        for (;;) {
-               memcpy(ready, sockbits, fd_size);
+               struct pollfd           pfd;
+               struct sockaddr_in      inetpeer;
+               int ret, msgsock, timeout;
+               socklen_t len;
+
+               pfd.fd = tcpsock;
+               pfd.events = POLLIN;
+               timeout = 10;
+
                if (connect_type_cnt > 1) {
-                       if (select(maxsock + 1,
-                           ready, NULL, NULL, NULL) < 1) {
-                               syslog(LOG_ERR, "select failed: %m");
+                       ret = poll(&pfd, 1, timeout);
+                       if (ret < 1) {
+                               syslog(LOG_ERR, "poll failed: %m");
                                return (1);
                        }
+                               
                }
-               if (tcpflag && FD_ISSET(tcpsock, ready)) {
+               
+               if (tcpflag) {
                        len = sizeof(inetpeer);
                        if ((msgsock = accept(tcpsock,
                            (struct sockaddr *)&inetpeer, &len)) < 0) {







On Wed, 23 Apr 2014 21:56:56 -0400
Peter Malone <pe...@petermalone.org> wrote:

Sounds good. I'll work on that tomorrow afternoon/evening.


On 04/23/14 21:55, Ted Unangst wrote:
On Wed, Apr 23, 2014 at 21:38, Peter Malone wrote:
Hi,

Similar to the others. malloc & memset replacement with calloc, this time
in sbin/nfsd/nfsd.c
        fd_size = howmany(maxsock + 1, NFDBITS) * sizeof(fd_mask);
-       sockbits = malloc(fd_size);
+       sockbits = calloc(1, fd_size);
        ready = malloc(fd_size);
As with ping6, I think this is better converted to poll.


Reply via email to