]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Retrieve FD_SETSIZE in a sane environment.
authorVincent Bernat <bernat@luffy.cx>
Fri, 12 Mar 2010 11:03:24 +0000 (12:03 +0100)
committerVincent Bernat <bernat@luffy.cx>
Fri, 12 Mar 2010 11:16:53 +0000 (12:16 +0100)
Since we import linux/if.h, in some environment, we may end up
importing kernel FD_SETSIZE that may be inappropriate (too large). For
example, on Sarge systems, FD_SETSIZE becomes 8192 instead of 1024 but
FD_ISSET is unable to handle this size.

configure.ac
m4/fdsetsize.m4 [new file with mode: 0644]
src/interfaces.c
src/lldpd.c

index ae684b3f37903b46a9c34fc99bcc0f25291d8b9a..705105417222335fec0ca191549f158a71caae54 100644 (file)
@@ -161,6 +161,7 @@ AC_TYPE_UINT16_T
 AC_TYPE_UINT32_T
 AC_TYPE_UINT8_T
 lldp_CHECK___PROGNAME
+lldp_CHECK_FD_SETSIZE
 
 # Checks for library functions.
 AC_FUNC_CHOWN
diff --git a/m4/fdsetsize.m4 b/m4/fdsetsize.m4
new file mode 100644 (file)
index 0000000..74197f8
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# lldp_CHECK_FD_SETSIZE
+#
+AC_DEFUN([lldp_CHECK_FD_SETSIZE],[
+  AC_CACHE_CHECK([real value of FD_SETSIZE], lldp_cv_check_fd_setsize, [
+    AC_RUN_IFELSE([
+       AC_LANG_PROGRAM(
+        [
+@%:@include <stdio.h>
+@%:@include <sys/select.h>
+@%:@include <sys/time.h>
+@%:@include <sys/types.h>
+@%:@include <unistd.h>
+       ],
+       [
+       FILE *fd;
+       if ((fd = fopen("conftest.out", "w")) == NULL) {
+          printf("Unable to create file conftest.out");
+          return 1;
+        }
+       fprintf(fd, "%d\n", FD_SETSIZE);
+       fclose(fd);
+       ])],
+       [ lldp_cv_check_fd_setsize=`cat conftest.out` ],
+       [ lldp_cv_check_fd_setsize="no" ])])
+  if test x"$lldp_cv_check_fd_setsize" = x"no"; then
+     AC_DEFINE([LLDPD_FD_SETSIZE], [FD_SETSIZE], [FD_SETSIZE for select()])
+  else
+     AC_DEFINE_UNQUOTED([LLDPD_FD_SETSIZE], $lldp_cv_check_fd_setsize,
+               [FD_SETSIZE for select()])
+  fi
+])
index 18a1e302bb4072c5295445bc9556d3ca1ac43f7a..5192ee1fd3102ebe99cb924ce2f3b01f7d457676 100644 (file)
@@ -602,7 +602,7 @@ static void
 iface_fds_close(struct lldpd *cfg, struct lldpd_hardware *hardware)
 {
        int i;
-       for (i=0; i < FD_SETSIZE; i++)
+       for (i=0; i < LLDPD_FD_SETSIZE; i++)
                if (FD_ISSET(i, &hardware->h_recvfds)) {
                        FD_CLR(i, &hardware->h_recvfds);
                        close(i);
index 6e7b974ef83f81fb8cea595c8396c5d93efc71d8..98f2770800b6d90682e5aa31e26b2f5ff6ded379 100644 (file)
 #include <arpa/inet.h>
 #include <net/if_arp.h>
 
+#if LLDPD_FD_SETSIZE != FD_SETSIZE
+# warning "FD_SETSIZE is set to an inconsistent value."
+#endif
+
 #ifdef USE_SNMP
 #include <net-snmp/net-snmp-config.h>
 #include <net-snmp/net-snmp-includes.h>
@@ -240,7 +244,7 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware)
                hardware->h_ops->cleanup(cfg, hardware);
        else {
                free(hardware->h_data);
-               for (i=0; i < FD_SETSIZE; i++)
+               for (i=0; i < LLDPD_FD_SETSIZE; i++)
                        if (FD_ISSET(i, &hardware->h_recvfds))
                                close(i);
                if (hardware->h_sendfd) close(hardware->h_sendfd);
@@ -482,7 +486,7 @@ lldpd_recv_all(struct lldpd *cfg)
                                continue;
                        /* This is quite expensive but we don't rely on internal
                         * structure of fd_set. */
-                       for (n = 0; n < FD_SETSIZE; n++)
+                       for (n = 0; n < LLDPD_FD_SETSIZE; n++)
                                if (FD_ISSET(n, &hardware->h_recvfds)) {
                                        FD_SET(n, &rfds);
                                        if (nfds < n)
@@ -520,10 +524,10 @@ lldpd_recv_all(struct lldpd *cfg)
                }
 #endif /* USE_SNMP */
                TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) {
-                       for (n = 0; n < FD_SETSIZE; n++)
+                       for (n = 0; n < LLDPD_FD_SETSIZE; n++)
                                if ((FD_ISSET(n, &hardware->h_recvfds)) &&
                                    (FD_ISSET(n, &rfds))) break;
-                       if (n == FD_SETSIZE) continue;
+                       if (n == LLDPD_FD_SETSIZE) continue;
                        if ((buffer = (char *)malloc(
                                        hardware->h_mtu)) == NULL) {
                                LLOG_WARN("failed to alloc reception buffer");