Index: source/smbd/server.c =================================================================== --- source/smbd/server.c (revision 3870) +++ source/smbd/server.c (working copy) @@ -186,7 +186,7 @@ int fd_listenset[FD_SETSIZE]; fd_set listen_set; int s; - int max_fd = 0; + int maxfd = 0; int i; char *ports; @@ -249,9 +249,6 @@ if(s == -1) return False; - if (max_fd < s) - max_fd = s; - /* ready to listen */ set_socket_options(s,"SO_KEEPALIVE"); set_socket_options(s,user_socket_options); @@ -265,6 +262,7 @@ return False; } FD_SET(s,&listen_set); + maxfd = MAX( maxfd, s); num_sockets++; if (num_sockets >= FD_SETSIZE) { @@ -307,6 +305,7 @@ fd_listenset[num_sockets] = s; FD_SET(s,&listen_set); + maxfd = MAX( maxfd, s); num_sockets++; @@ -341,7 +340,7 @@ memcpy((char *)&lfds, (char *)&listen_set, sizeof(listen_set)); - num = sys_select(max_fd+1,&lfds,NULL,NULL,NULL); + num = sys_select(maxfd+1,&lfds,NULL,NULL,NULL); if (num == -1 && errno == EINTR) { if (got_sig_term) { Index: source/nmbd/nmbd_packets.c =================================================================== --- source/nmbd/nmbd_packets.c (revision 3870) +++ source/nmbd/nmbd_packets.c (working copy) @@ -1635,16 +1635,6 @@ } /**************************************************************************** - Check and if required set the highest fd. -***************************************************************************/ - -void check_set_maxfd( int *maxfd, int fd) -{ - if ( *maxfd < fd ) - *maxfd = fd; -} - -/**************************************************************************** Create an fd_set containing all the sockets in the subnet structures, plus the broadcast sockets. ***************************************************************************/ @@ -1682,25 +1672,25 @@ /* Add in the broadcast socket on 137. */ FD_SET(ClientNMB,pset); sock_array[num++] = ClientNMB; - check_set_maxfd( maxfd, ClientNMB); + *maxfd = MAX( *maxfd, ClientNMB); /* Add in the 137 sockets on all the interfaces. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { FD_SET(subrec->nmb_sock,pset); sock_array[num++] = subrec->nmb_sock; - check_set_maxfd( maxfd, subrec->nmb_sock); + *maxfd = MAX( *maxfd, subrec->nmb_sock); } /* Add in the broadcast socket on 138. */ FD_SET(ClientDGRAM,pset); sock_array[num++] = ClientDGRAM; - check_set_maxfd( maxfd, ClientDGRAM); + *maxfd = MAX( *maxfd, ClientDGRAM); /* Add in the 138 sockets on all the interfaces. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { FD_SET(subrec->dgram_sock,pset); sock_array[num++] = subrec->dgram_sock; - check_set_maxfd( maxfd, subrec->dgram_sock); + *maxfd = ( *maxfd, subrec->dgram_sock); } *listen_number = (count*2) + 2; @@ -1725,7 +1715,7 @@ static int listen_number = 0; static int *sock_array = NULL; int i; - int maxfd = 0; + static int maxfd = 0; fd_set fds; int selrtn; @@ -1748,7 +1738,7 @@ dns_fd = asyncdns_fd(); if (dns_fd != -1) { FD_SET(dns_fd, &fds); - check_set_maxfd( &maxfd, dns_fd); + maxfd = MAX( maxfd, dns_fd); } #endif Index: source/wrepld/server.c =================================================================== --- source/wrepld/server.c (revision 3870) +++ source/wrepld/server.c (working copy) @@ -164,7 +164,7 @@ plus the broadcast sockets. ***************************************************************************/ -static BOOL create_listen_fdset(void) +static BOOL create_listen_fdset( int *maxfd) { int i; int num_interfaces = iface_count(); @@ -221,6 +221,7 @@ } add_fd_to_sock_array(s); FD_SET(s, listen_set); + *maxfd = MAX( *maxfd, s); } } else { /* Just bind to 0.0.0.0 - accept connections from anywhere. */ @@ -243,6 +244,7 @@ add_fd_to_sock_array(s); FD_SET(s, listen_set); + *maxfd = MAX( *maxfd, s); } return True; @@ -346,10 +348,11 @@ int num_interfaces = iface_count(); fd_set fds; int i, num, s, new_s; + static int maxfd = 0; struct timeval timeout; if(listen_set == NULL) { - if(!create_listen_fdset()) { + if(!create_listen_fdset( &maxfd)) { DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); return True; } @@ -364,7 +367,7 @@ BlockSignals(False, SIGTERM); - num = sys_select(FD_SETSIZE, &fds, NULL, NULL, &timeout); + num = sys_select(maxfd+1, &fds, NULL, NULL, &timeout); /* We can only take signals when we are in the select - block them again here. */ @@ -397,6 +400,7 @@ set_socket_options(new_s, user_socket_options); FD_SET(new_s, listen_set); add_fd_to_sock_array(new_s); + maxfd = MAX( maxfd, new_s); } }