]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Check BUGGY_CMSG_MACROS in configure.
authorTimo Sirainen <tss@iki.fi>
Thu, 22 Jul 2004 19:37:25 +0000 (22:37 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 22 Jul 2004 19:37:25 +0000 (22:37 +0300)
--HG--
branch : HEAD

configure.in
src/lib/fdpass.c

index 28f49cbdde5ea02cbfe03cd61ce56b100ceabb21..f9d795b4b10fdbaba193f898740f69e8c178a20a 100644 (file)
@@ -1,7 +1,7 @@
 AC_INIT(src)
 
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(dovecot, 1.0-test20)
+AM_INIT_AUTOMAKE(dovecot, 1.0-test29)
 
 AM_MAINTAINER_MODE
 
@@ -752,6 +752,64 @@ AC_TRY_RUN([
   AC_DEFINE(MMAP_CONFLICTS_WRITE,, [Define if shared mmaps don't get updated by write()s])
 ])
 
+dnl * see if fd passing works
+AC_MSG_CHECKING([whether fd passing works])
+for i in 1 2; do
+  old_cflags="$CFLAGS"
+  CFLAGS="$CFLAGS -I$srcdir/src/lib $srcdir/src/lib/fdpass.c"
+  if test $i = 2; then
+    CFLAGS="$CFLAGS -DBUGGY_CMSG_MACROS"
+  fi
+
+  AC_TRY_RUN([
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <sys/wait.h>
+    #include <sys/stat.h>
+    #include <unistd.h>
+    #include <fcntl.h>
+    #include "fdpass.h"
+    
+    int main(void)
+    {
+           int fd[2], send_fd, recv_fd, status;
+           struct stat st, st2;
+           char data;
+    
+           send_fd = open("conftest.fdpass", O_CREAT|O_WRONLY);
+           if (send_fd == -1) return 2;
+           unlink("conftest.fdpass");
+           if (fstat(send_fd, &st) < 0) return 2;
+           if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) return 2;
+    
+           switch (fork()) {
+           case -1:
+                   return 2;
+           case 0:
+                   if (fd_send(fd[0], send_fd, &data, 1) != 1) return 2;
+                   wait(&status);
+                   return status;
+           default:
+                   if (fd_read(fd[1], &data, 1, &recv_fd) != 1) return 1;
+                   if (fstat(recv_fd, &st2) < 0) return 2;
+                   return st.st_ino == st2.st_ino ? 0 : 1;
+           }
+    }
+  ], [
+    CFLAGS=$old_cflags
+    if test $i = 2; then
+      AC_DEFINE(BUGGY_CMSG_MACROS,, Define if you have buggy CMSG macros)
+    fi
+    AC_MSG_RESULT(yes)
+    break
+  ], [
+    dnl no, try with BUGGY_CMSG_MACROS
+    CFLAGS=$old_cflags
+    if test $i = 2; then
+      AC_MSG_RESULT(no)
+    fi
+  ])
+done
 
 dnl * Solaris compatible sendfile()
 AC_CHECK_LIB(sendfile, sendfile, [
index e7f2fe499df1619cbf9676a53f2345ef0a45b435..a5ba468b36fb0b0160975dd61b2e94283d37f4be 100644 (file)
@@ -6,7 +6,7 @@
    This isn't fully portable, but pretty much all UNIXes nowadays should
    support this. If you're having runtime problems with fd_read(), check the
    end of fd_read() and play with the if condition. If you're having problems
-   with fd_send(), try defining BUGGY_CMSG_HEADERS.
+   with fd_send(), try defining BUGGY_CMSG_MACROS.
 
    If this file doesn't compile at all, you should check if this is supported
    in your system at all. It may require some extra #define to enable it.
 #  define _XOPEN_SOURCE_EXTENDED /* for Tru64, breaks AIX */
 #endif
 
-#include "lib.h"
-#include "fdpass.h"
+#include <string.h>
+#include <limits.h>
+#include <sys/types.h>
 
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/uio.h>
 
+#ifdef HAVE_CONFIG_H
+#  include "lib.h"
+#else
+#  define i_assert(x)
+#endif
+#include "fdpass.h"
+
 /* RFC 2292 defines CMSG_*() macros, but some operating systems don't have them
    so we'll define our own if they don't exist.
 
    correct in case it's sometimes needed..
 */
 
-#ifdef BUGGY_CMSG_HEADERS
+#ifdef BUGGY_CMSG_MACROS
 /* Some OSes have broken CMSG macros in 64bit systems. The macros use 64bit
    alignmentation while kernel uses 32bit alignmentation. */
 #  undef CMSG_SPACE
 #  undef CMSG_LEN
 #  undef CMSG_DATA
 #  define CMSG_DATA(cmsg) ((char *)((cmsg) + 1))
-#  define _CMSG_DATA_ALIGNMENT sizeof(uint32_t)
-#  define _CMSG_HDR_ALIGNMENT sizeof(uint32_t)
+#  define _CMSG_DATA_ALIGNMENT 4
+#  define _CMSG_HDR_ALIGNMENT 4
 #endif
 
 #ifndef CMSG_SPACE
@@ -93,7 +101,7 @@ ssize_t fd_send(int handle, int send_fd, const void *data, size_t size)
        char buf[CMSG_SPACE(sizeof(int))];
 
        /* at least one byte is required to be sent with fd passing */
-       i_assert(size > 0 && size < SSIZE_T_MAX);
+       i_assert(size > 0 && size < INT_MAX);
 
        memset(&msg, 0, sizeof(struct msghdr));
 
@@ -149,7 +157,7 @@ ssize_t fd_read(int handle, void *data, size_t size, int *fd)
        ssize_t ret;
        char buf[CMSG_SPACE(sizeof(int))];
 
-       i_assert(size > 0 && size < SSIZE_T_MAX);
+       i_assert(size > 0 && size < INT_MAX);
 
        memset(&msg, 0, sizeof (struct msghdr));