changeset 2349:b65456de1b49 HEAD

Check BUGGY_CMSG_MACROS in configure.
author Timo Sirainen <tss@iki.fi>
date Thu, 22 Jul 2004 22:37:25 +0300
parents 65433665256d
children 1371d41c375f
files configure.in src/lib/fdpass.c
diffstat 2 files changed, 75 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Thu Jul 22 21:59:14 2004 +0300
+++ b/configure.in	Thu Jul 22 22:37:25 2004 +0300
@@ -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_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, [
--- a/src/lib/fdpass.c	Thu Jul 22 21:59:14 2004 +0300
+++ b/src/lib/fdpass.c	Thu Jul 22 22:37:25 2004 +0300
@@ -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.
@@ -23,13 +23,21 @@
 #  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.
 
@@ -52,15 +60,15 @@
    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 @@
 	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 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));