OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
PATCH: fcntl F_DUPFD: Invalid argument on 64-bit Solaris

From: Wietse Venema (wietseporcupine.org)
Date: Mon Apr 02 2007 - 14:38:43 CDT


Portability (introduced 20070212): the workaround for non-existent
library bugs with descriptors >= FD_SETSIZE broke with "fcntl
F_DUPFD: Invalid argument" on 64-bit Solaris. Files:
master/multi_server.c, *qmgr/qmgr_transport.c.

Lesson: don't add workarounds before there is a known need.

        Wietse

diff --exclude=man --exclude=html --exclude=README_FILES --exclude=.indent.pro --exclude=Makefile.in -bcr /var/tmp/postfix-2.5-20070328/src/master/multi_server.c ./src/master/multi_server.c
*** /var/tmp/postfix-2.5-20070328/src/master/multi_server.c Wed Mar 14 15:35:47 2007
--- ./src/master/multi_server.c Mon Apr 2 15:09:09 2007
***************
*** 336,349 ****
      char *tmp;
  
  #if defined(F_DUPFD) && (EVENTS_STYLE != EVENTS_STYLE_SELECT)
      int new_fd;
  
      /*
       * Leave some handles < FD_SETSIZE for DBMS libraries, in the unlikely
       * case of a multi-server with a thousand clients.
       */
! if (fd < FD_SETSIZE / 8) {
! if ((new_fd = fcntl(fd, F_DUPFD, FD_SETSIZE / 8)) < 0)
              msg_fatal("fcntl F_DUPFD: %m");
          (void) close(fd);
          fd = new_fd;
--- 336,352 ----
      char *tmp;
  
  #if defined(F_DUPFD) && (EVENTS_STYLE != EVENTS_STYLE_SELECT)
+ #ifndef THRESHOLD_FD_WORKAROUND
+ #define THRESHOLD_FD_WORKAROUND 128
+ #endif
      int new_fd;
  
      /*
       * Leave some handles < FD_SETSIZE for DBMS libraries, in the unlikely
       * case of a multi-server with a thousand clients.
       */
! if (fd < THRESHOLD_FD_WORKAROUND) {
! if ((new_fd = fcntl(fd, F_DUPFD, THRESHOLD_FD_WORKAROUND)) < 0)
              msg_fatal("fcntl F_DUPFD: %m");
          (void) close(fd);
          fd = new_fd;
diff --exclude=man --exclude=html --exclude=README_FILES --exclude=.indent.pro --exclude=Makefile.in -bcr /var/tmp/postfix-2.5-20070328/src/oqmgr/qmgr_transport.c ./src/oqmgr/qmgr_transport.c
*** /var/tmp/postfix-2.5-20070328/src/oqmgr/qmgr_transport.c Sat Feb 17 20:09:55 2007
--- ./src/oqmgr/qmgr_transport.c Mon Apr 2 15:08:18 2007
***************
*** 342,349 ****
          return;
      }
  #if (EVENTS_STYLE != EVENTS_STYLE_SELECT) && defined(VSTREAM_CTL_DUPFD)
      vstream_control(alloc->stream,
! VSTREAM_CTL_DUPFD, FD_SETSIZE / 8,
                      VSTREAM_CTL_END);
  #endif
      event_enable_read(vstream_fileno(alloc->stream), qmgr_transport_event,
--- 342,352 ----
          return;
      }
  #if (EVENTS_STYLE != EVENTS_STYLE_SELECT) && defined(VSTREAM_CTL_DUPFD)
+ #ifndef THRESHOLD_FD_WORKAROUND
+ #define THRESHOLD_FD_WORKAROUND 128
+ #endif
      vstream_control(alloc->stream,
! VSTREAM_CTL_DUPFD, THRESHOLD_FD_WORKAROUND,
                      VSTREAM_CTL_END);
  #endif
      event_enable_read(vstream_fileno(alloc->stream), qmgr_transport_event,
diff --exclude=man --exclude=html --exclude=README_FILES --exclude=.indent.pro --exclude=Makefile.in -bcr /var/tmp/postfix-2.5-20070328/src/qmgr/qmgr_transport.c ./src/qmgr/qmgr_transport.c
*** /var/tmp/postfix-2.5-20070328/src/qmgr/qmgr_transport.c Sat Feb 17 20:10:04 2007
--- ./src/qmgr/qmgr_transport.c Mon Apr 2 15:08:32 2007
***************
*** 347,354 ****
          return;
      }
  #if (EVENTS_STYLE != EVENTS_STYLE_SELECT) && defined(VSTREAM_CTL_DUPFD)
      vstream_control(alloc->stream,
! VSTREAM_CTL_DUPFD, FD_SETSIZE / 8,
                      VSTREAM_CTL_END);
  #endif
      event_enable_read(vstream_fileno(alloc->stream), qmgr_transport_event,
--- 347,357 ----
          return;
      }
  #if (EVENTS_STYLE != EVENTS_STYLE_SELECT) && defined(VSTREAM_CTL_DUPFD)
+ #ifndef THRESHOLD_FD_WORKAROUND
+ #define THRESHOLD_FD_WORKAROUND 128
+ #endif
      vstream_control(alloc->stream,
! VSTREAM_CTL_DUPFD, THRESHOLD_FD_WORKAROUND,
                      VSTREAM_CTL_END);
  #endif
      event_enable_read(vstream_fileno(alloc->stream), qmgr_transport_event,