From 6896772b763d435753c40e73a59eb907bee3e9a1 Mon Sep 17 00:00:00 2001 From: Wietse Venema Date: Mon, 25 Mar 2013 00:00:00 -0500 Subject: [PATCH] postfix-2.11-20130325 --- postfix/HISTORY | 11 +++++++++++ postfix/makedefs | 8 +++++++- postfix/src/global/mail_version.h | 2 +- postfix/src/util/read_wait.c | 22 ++++++++++++++++------ postfix/src/util/readable.c | 21 ++++++++++++++++----- postfix/src/util/sys_defs.h | 26 +++++++++++++++++++------- postfix/src/util/writable.c | 21 ++++++++++++++++----- postfix/src/util/write_wait.c | 21 ++++++++++++++++----- 8 files changed, 102 insertions(+), 30 deletions(-) diff --git a/postfix/HISTORY b/postfix/HISTORY index 0c17de0bf..9194cb2b6 100644 --- a/postfix/HISTORY +++ b/postfix/HISTORY @@ -18346,3 +18346,14 @@ Apologies for any names omitted. and TLS policies. Viktor Dukhovni. Files: src/dns/Makefile.in, src/dns/dns.h, src/dns/dns_lookup.c, src/dns/dns_rr.c, src/dns/dns_strtype.c, src/dns/test_dns_lookup.c. + +20130325 + + Portability: on MacOS X, use kqueue() for event handling + but use select() instead of poll() for read/write timeouts + (with a workaround to handle file decriptors >=FD_SETSIZE). + Files: util/sys_defs.h, util/readable.c, util/writable.c, + util/read_wait.c, util/write_wait.c. + + Portability: support for NetBSD 5.x, NetBSD 6.x and DragonFly + BSD. Viktor Dukhovni. Files: makedefs, src/util/sys_defs.h. diff --git a/postfix/makedefs b/postfix/makedefs index 71f5008d1..169a054c6 100644 --- a/postfix/makedefs +++ b/postfix/makedefs @@ -155,6 +155,8 @@ case "$SYSTEM.$RELEASE" in ;; FreeBSD.9*) SYSTYPE=FREEBSD9 ;; + DragonFly.*) SYSTYPE=DRAGONFLY + ;; OpenBSD.2*) SYSTYPE=OPENBSD2 ;; OpenBSD.3*) SYSTYPE=OPENBSD3 @@ -173,6 +175,10 @@ case "$SYSTEM.$RELEASE" in ;; NetBSD.4*) SYSTYPE=NETBSD4 ;; + NetBSD.5*) SYSTYPE=NETBSD5 + ;; + NetBSD.6*) SYSTYPE=NETBSD6 + ;; BSD/OS.2*) SYSTYPE=BSDI2 ;; BSD/OS.3*) SYSTYPE=BSDI3 @@ -476,7 +482,7 @@ ReliantUNIX-?.5.43) SYSTYPE=ReliantUnix543 *) CCARGS="$CCARGS -DRESOLVE_H_NEEDS_ARPA_NAMESER_COMPAT_H";; esac # kqueue and/or poll are broken in MacOS X 10.5 (Darwin 9). - # kqueue and poll work in Mac OS X 10.8 (Darwin 12). + # kqueue works in Mac OS X 10.8 (Darwin 12). case $RELEASE in ?.*|1[0-1].*) CCARGS="$CCARGS -DNO_KQUEUE";; esac diff --git a/postfix/src/global/mail_version.h b/postfix/src/global/mail_version.h index 5409efba0..f519f386d 100644 --- a/postfix/src/global/mail_version.h +++ b/postfix/src/global/mail_version.h @@ -20,7 +20,7 @@ * Patches change both the patchlevel and the release date. Snapshots have no * patchlevel; they change the release date only. */ -#define MAIL_RELEASE_DATE "20130324" +#define MAIL_RELEASE_DATE "20130325" #define MAIL_VERSION_NUMBER "2.11" #ifdef SNAPSHOT diff --git a/postfix/src/util/read_wait.c b/postfix/src/util/read_wait.c index ff2102f98..096b38a51 100644 --- a/postfix/src/util/read_wait.c +++ b/postfix/src/util/read_wait.c @@ -15,8 +15,8 @@ /* /* Arguments: /* .IP fd -/* File descriptor in the range 0..FD_SETSIZE (on systems that -/* need to use select(2)). +/* File descriptor. With implementations based on select(), +/* a best effort is made to handle descriptors >=FD_SETSIZE. /* .IP timeout /* If positive, deadline in seconds. A zero value effects a poll. /* A negative value means wait until something happens. @@ -62,17 +62,21 @@ int read_wait(int fd, int timeout) { -#ifndef USE_SYSV_POLL +#if defined(NO_SYSV_POLL) fd_set read_fds; fd_set except_fds; struct timeval tv; struct timeval *tp; + int temp_fd = -1; /* * Sanity checks. */ - if (FD_SETSIZE <= fd) - msg_panic("descriptor %d does not fit FD_SETSIZE %d", fd, FD_SETSIZE); + if (FD_SETSIZE <= fd) { + if ((temp_fd = dup(fd)) < 0 || temp_fd >= FD_SETSIZE) + msg_fatal("descriptor %d does not fit FD_SETSIZE %d", fd, FD_SETSIZE); + fd = temp_fd; + } /* * Use select() so we do not depend on alarm() and on signal() handlers. @@ -99,13 +103,17 @@ int read_wait(int fd, int timeout) msg_fatal("select: %m"); continue; case 0: + if (temp_fd != -1) + (void) close(temp_fd); errno = ETIMEDOUT; return (-1); default: + if (temp_fd != -1) + (void) close(temp_fd); return (0); } } -#else +#elif defined(USE_SYSV_POLL) /* * System-V poll() is optimal for polling a few descriptors. @@ -132,5 +140,7 @@ int read_wait(int fd, int timeout) return (0); } } +#else +#error "define USE_SYSV_POLL or NO_SYSV_POLL" #endif } diff --git a/postfix/src/util/readable.c b/postfix/src/util/readable.c index 7d297403b..00756cc78 100644 --- a/postfix/src/util/readable.c +++ b/postfix/src/util/readable.c @@ -14,7 +14,8 @@ /* /* Arguments: /* .IP fd -/* File descriptor in the range 0..FD_SETSIZE. +/* File descriptor. With implementations based on select(), +/* a best effort is made to handle descriptors >=FD_SETSIZE. /* DIAGNOSTICS /* All system call errors are fatal. /* LICENSE @@ -54,16 +55,20 @@ int readable(int fd) { -#ifndef USE_SYSV_POLL +#if defined(NO_SYSV_POLL) struct timeval tv; fd_set read_fds; fd_set except_fds; + int temp_fd = -1; /* * Sanity checks. */ - if (fd >= FD_SETSIZE) - msg_fatal("fd %d does not fit in FD_SETSIZE", fd); + if (fd >= FD_SETSIZE) { + if ((temp_fd = dup(fd)) < 0 || temp_fd >= FD_SETSIZE) + msg_fatal("fd %d does not fit in FD_SETSIZE", fd); + fd = temp_fd; + } /* * Initialize. @@ -85,12 +90,16 @@ int readable(int fd) msg_fatal("select: %m"); continue; default: + if (temp_fd != -1) + (void) close(temp_fd); return (FD_ISSET(fd, &read_fds)); case 0: + if (temp_fd != -1) + (void) close(temp_fd); return (0); } } -#else +#elif defined(USE_SYSV_POLL) /* * System-V poll() is optimal for polling a few descriptors. @@ -115,5 +124,7 @@ int readable(int fd) return (1); } } +#else +#error "define USE_SYSV_POLL or NO_SYSV_POLL" #endif } diff --git a/postfix/src/util/sys_defs.h b/postfix/src/util/sys_defs.h index 00cbdc2e1..a32c351be 100644 --- a/postfix/src/util/sys_defs.h +++ b/postfix/src/util/sys_defs.h @@ -30,8 +30,8 @@ || defined(OPENBSD2) || defined(OPENBSD3) || defined(OPENBSD4) \ || defined(OPENBSD5) \ || defined(NETBSD1) || defined(NETBSD2) || defined(NETBSD3) \ - || defined(NETBSD4) \ - || defined(EKKOBSD1) + || defined(NETBSD4) || defined(NETBSD5) || defined(NETBSD6) \ + || defined(EKKOBSD1) || defined(DRAGONFLY) #define SUPPORTED #include #include @@ -165,9 +165,19 @@ #define HAS_FUTIMES #endif +#if defined(__DragonFly__) +#define HAS_DEV_URANDOM +#define HAS_ISSETUGID +#define HAS_FUTIMES +#define SOCKADDR_SIZE socklen_t +#define SOCKOPT_SIZE socklen_t +#define HAS_DUPLEX_PIPE +#endif + #if (defined(__NetBSD_Version__) && __NetBSD_Version__ >= 105000000) \ || (defined(__FreeBSD__) && __FreeBSD__ >= 4) \ || (defined(OpenBSD) && OpenBSD >= 200003) \ + || defined(__DragonFly__) \ || defined(USAGI_LIBINET6) #ifndef NO_IPV6 # define HAS_IPV6 @@ -176,14 +186,16 @@ #if (defined(__FreeBSD_version) && __FreeBSD_version >= 300000) \ || (defined(__NetBSD_Version__) && __NetBSD_Version__ >= 103000000) \ - || (defined(OpenBSD) && OpenBSD >= 199700) /* OpenBSD 2.0?? */ + || (defined(OpenBSD) && OpenBSD >= 199700) /* OpenBSD 2.0?? */ \ + || defined(__DragonFly__) # define USE_SYSV_POLL #endif #ifndef NO_KQUEUE # if (defined(__FreeBSD_version) && __FreeBSD_version >= 410000) \ || (defined(__NetBSD_Version__) && __NetBSD_Version__ >= 200000000) \ - || (defined(OpenBSD) && OpenBSD >= 200105) /* OpenBSD 2.9 */ + || (defined(OpenBSD) && OpenBSD >= 200105) /* OpenBSD 2.9 */ \ + || defined(__DragonFly__) # define EVENTS_STYLE EVENTS_STYLE_KQUEUE # endif #endif @@ -242,7 +254,7 @@ #define SOCKOPT_SIZE socklen_t #ifndef NO_KQUEUE # define EVENTS_STYLE EVENTS_STYLE_KQUEUE -# define USE_SYSV_POLL +# define NO_SYSV_POLL #endif #ifndef NO_POSIX_GETPW_R # define HAVE_POSIX_GETPW_R @@ -1368,8 +1380,8 @@ extern int inet_pton(int, const char *, void *); #define EVENTS_STYLE_DEVPOLL 3 /* Solaris /dev/poll */ #define EVENTS_STYLE_EPOLL 4 /* Linux epoll */ -#if !defined(USE_SYSV_POLL) && (EVENTS_STYLE != EVENTS_STYLE_SELECT) -#error "need USE_SYSV_POLL with EVENTS_STYLE != EVENTS_STYLE_SELECT" +#if !defined(USE_SYSV_POLL) && !defined(NO_SYSV_POLL) && (EVENTS_STYLE != EVENTS_STYLE_SELECT) +#error "need USE_SYSV_POLL or NO_SYSV_POLL with EVENTS_STYLE != EVENTS_STYLE_SELECT" #endif /* diff --git a/postfix/src/util/writable.c b/postfix/src/util/writable.c index f37eb2229..a388dcbda 100644 --- a/postfix/src/util/writable.c +++ b/postfix/src/util/writable.c @@ -14,7 +14,8 @@ /* /* Arguments: /* .IP fd -/* File descriptor in the range 0..FD_SETSIZE. +/* File descriptor. With implementations based on select(), +/* a best effort is made to handle descriptors >=FD_SETSIZE. /* DIAGNOSTICS /* All system call errors are fatal. /* LICENSE @@ -54,16 +55,20 @@ int writable(int fd) { -#ifndef USE_SYSV_POLL +#if defined(NO_SYSV_POLL) struct timeval tv; fd_set write_fds; fd_set except_fds; + int temp_fd = -1; /* * Sanity checks. */ - if (fd >= FD_SETSIZE) - msg_fatal("fd %d does not fit in FD_SETSIZE", fd); + if (fd >= FD_SETSIZE) { + if ((temp_fd = dup(fd)) < 0 || temp_fd >= FD_SETSIZE) + msg_fatal("fd %d does not fit in FD_SETSIZE", fd); + fd = temp_fd; + } /* * Initialize. @@ -85,12 +90,16 @@ int writable(int fd) msg_fatal("select: %m"); continue; default: + if (temp_fd != -1) + (void) close(temp_fd); return (FD_ISSET(fd, &write_fds)); case 0: + if (temp_fd != -1) + (void) close(temp_fd); return (0); } } -#else +#elif defined(USE_SYSV_POLL) /* * System-V poll() is optimal for polling a few descriptors. @@ -115,5 +124,7 @@ int writable(int fd) return (1); } } +#else +#error "define USE_SYSV_POLL or NO_SYSV_POLL" #endif } diff --git a/postfix/src/util/write_wait.c b/postfix/src/util/write_wait.c index 1a42c126e..cf6dde15b 100644 --- a/postfix/src/util/write_wait.c +++ b/postfix/src/util/write_wait.c @@ -15,7 +15,8 @@ /* /* Arguments: /* .IP fd -/* File descriptor in the range 0..FD_SETSIZE. +/* File descriptor. With implementations based on select(), +/* a best effort is made to handle descriptors >=FD_SETSIZE. /* .IP timeout /* If positive, deadline in seconds. A zero value effects a poll. /* A negative value means wait until something happens. @@ -61,17 +62,21 @@ int write_wait(int fd, int timeout) { -#ifndef USE_SYSV_POLL +#if defined(NO_SYSV_POLL) fd_set write_fds; fd_set except_fds; struct timeval tv; struct timeval *tp; + int temp_fd = -1; /* * Sanity checks. */ - if (FD_SETSIZE <= fd) - msg_panic("descriptor %d does not fit FD_SETSIZE %d", fd, FD_SETSIZE); + if (FD_SETSIZE <= fd) { + if ((temp_fd = dup(fd)) < 0 || temp_fd >= FD_SETSIZE) + msg_fatal("descriptor %d does not fit FD_SETSIZE %d", fd, FD_SETSIZE); + fd = temp_fd; + } /* * Guard the write() with select() so we do not depend on alarm() and on @@ -98,13 +103,17 @@ int write_wait(int fd, int timeout) msg_fatal("select: %m"); continue; case 0: + if (temp_fd != -1) + (void) close(temp_fd); errno = ETIMEDOUT; return (-1); default: + if (temp_fd != -1) + (void) close(temp_fd); return (0); } } -#else +#elif defined(USE_SYSV_POLL) /* * System-V poll() is optimal for polling a few descriptors. @@ -131,5 +140,7 @@ int write_wait(int fd, int timeout) return (0); } } +#else +#error "define USE_SYSV_POLL or NO_SYSV_POLL" #endif } -- 2.47.3