[Xcb-commit] libxcb: 3 commits - configure.ac src

Alan Coopersmith alanc at kemper.freedesktop.org
Fri Nov 8 05:25:39 CET 2013


 configure.ac   |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 src/xcb_conn.c |   15 ++++++++++-----
 src/xcb_in.c   |   24 +++++++++---------------
 src/xcbint.h   |    5 -----
 4 files changed, 63 insertions(+), 33 deletions(-)

New commits:
commit e8663a935890ff366f49e356211049dfd0d9756a
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Nov 7 20:23:27 2013 -0800

    Check if we need to define _XOPEN_SOURCE for struct msghdr.msg_control
    
    Required to expose the structure members in Solaris headers, since it
    was an XPG4/UNIX95 addition to the Solaris ABI.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/configure.ac b/configure.ac
index d054a43..87804ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,6 +90,40 @@ xauto)
 	;;
 esac
 
+# XPG4v2/UNIX95 added msg_control - check to see if we need to define
+# _XOPEN_SOURCE to get it (such as on Solaris)
+AC_CHECK_MEMBER([struct msghdr.msg_control], [], [],
+                 [
+AC_INCLUDES_DEFAULT
+#include <sys/socket.h>
+                 ])
+# First try for Solaris in C99 compliant mode, which requires XPG6/UNIX03
+if test "x$ac_cv_member_struct_msghdr_msg_control" = xno; then
+    unset ac_cv_member_struct_msghdr_msg_control
+    AC_MSG_NOTICE([trying again with _XOPEN_SOURCE=600])
+    AC_CHECK_MEMBER([struct msghdr.msg_control],
+                    [AC_DEFINE([_XOPEN_SOURCE], [600],
+                       [Defined if needed to expose struct msghdr.msg_control])
+                    ], [], [
+#define _XOPEN_SOURCE 600
+AC_INCLUDES_DEFAULT
+#include <sys/socket.h>
+                     ])
+fi
+# If that didn't work, fall back to XPG5/UNIX98 with C89
+if test "x$ac_cv_member_struct_msghdr_msg_control" = xno; then
+    unset ac_cv_member_struct_msghdr_msg_control
+    AC_MSG_NOTICE([trying again with _XOPEN_SOURCE=500])
+    AC_CHECK_MEMBER([struct msghdr.msg_control],
+                    [AC_DEFINE([_XOPEN_SOURCE], [500],
+                       [Defined if needed to expose struct msghdr.msg_control])
+                    ], [sendfds="no"], [
+#define _XOPEN_SOURCE 500
+AC_INCLUDES_DEFAULT
+#include <sys/socket.h>
+                     ])
+fi
+
 case x$sendfds in
 xyes)
         AC_DEFINE([HAVE_SENDMSG],1,[Define if your platform supports sendmsg])
commit af8067cbf48561f1e2d43e153292e68e0376a8f9
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Nov 7 17:36:01 2013 -0800

    Add configure option to enable or disable fd passing with sendmsg
    
    --disable-sendfds or --enable-sendfds
    
    By default, configure auto-detects based on whether your system
    supports sendmsg at all.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/configure.ac b/configure.ac
index 86efc3a..d054a43 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,14 +81,16 @@ AC_HEADER_STDC
 AC_SEARCH_LIBS(getaddrinfo, socket)
 AC_SEARCH_LIBS(connect, socket)
 
-have_sendmsg="no"
-case $host_os in
-linux*)
-        AC_SEARCH_LIBS(sendmsg, socket, [have_sendmsg="yes"], [have_sendmsg="no"])
-        ;;
+AC_ARG_ENABLE(sendfds, AS_HELP_STRING([--disable-sendfds], [Support FD passing (default: auto)]),
+	      [sendfds=$enableval], [sendfds=auto])
+
+case x$sendfds in
+xauto)
+	AC_SEARCH_LIBS(sendmsg, socket, [sendfds="yes"], [sendfds="no"])
+	;;
 esac
 
-case x$have_sendmsg in
+case x$sendfds in
 xyes)
         AC_DEFINE([HAVE_SENDMSG],1,[Define if your platform supports sendmsg])
         ;;
@@ -184,7 +186,7 @@ XCB_EXTENSION(Composite, "yes")
 XCB_EXTENSION(Damage, "yes")
 XCB_EXTENSION(DPMS, "yes")
 XCB_EXTENSION(DRI2, "yes")
-XCB_EXTENSION(DRI3, "$have_sendmsg")
+XCB_EXTENSION(DRI3, "$sendfds")
 XCB_EXTENSION(GLX, "yes")
 XCB_EXTENSION(Present, "yes")
 XCB_EXTENSION(RandR, "yes")
@@ -267,7 +269,7 @@ echo "  Package: ${PACKAGE_NAME} ${PACKAGE_VERSION}"
 echo ""
 echo "  Configuration"
 echo "    XDM support.........: ${have_xdmcp}"
-echo "    sendmsg fd passing..: ${have_sendmsg}"
+echo "    sendmsg fd passing..: ${sendfds}"
 echo "    Build unit tests....: ${HAVE_CHECK}"
 echo "      with html results.: ${HTML_CHECK_RESULT}"
 echo "    XCB buffer size.....: ${xcb_queue_buffer_size}"
commit 83f28ef8655acff746eab64eabe2e31f8cf0c892
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Nov 7 17:28:45 2013 -0800

    Switch to using the CMSG_* macros for FD passing
    
    Use these instead of computing the values directly so that it might
    work on BSD or other non-Linux systems
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index c06c7cb..50e7fb6 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -216,18 +216,23 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
 
 #if HAVE_SENDMSG
     if (c->out.out_fd.nfd) {
+        char cmsgbuf[CMSG_SPACE(sizeof(int) * XCB_MAX_PASS_FD)];
         struct msghdr msg = {
             .msg_name = NULL,
             .msg_namelen = 0,
             .msg_iov = *vector,
             .msg_iovlen = n,
-            .msg_control = &c->out.out_fd,
-            .msg_controllen = sizeof (struct cmsghdr) + c->out.out_fd.nfd * sizeof (int),
+            .msg_control = cmsgbuf,
+            .msg_controllen = CMSG_LEN(c->out.out_fd.nfd * sizeof (int)),
         };
         int i;
-        c->out.out_fd.cmsghdr.cmsg_len = msg.msg_controllen;
-        c->out.out_fd.cmsghdr.cmsg_level = SOL_SOCKET;
-        c->out.out_fd.cmsghdr.cmsg_type = SCM_RIGHTS;
+        struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
+
+        hdr->cmsg_len = msg.msg_controllen;
+        hdr->cmsg_level = SOL_SOCKET;
+        hdr->cmsg_type = SCM_RIGHTS;
+        memcpy(CMSG_DATA(hdr), c->out.out_fd.fd, c->out.out_fd.nfd * sizeof (int));
+
         n = sendmsg(c->fd, &msg, 0);
         if(n < 0 && errno == EAGAIN)
             return 1;
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 839f615..8c3a58c 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -888,17 +888,14 @@ int _xcb_in_read(xcb_connection_t *c)
         .iov_base = c->in.queue + c->in.queue_len,
         .iov_len = sizeof(c->in.queue) - c->in.queue_len,
     };
-    struct {
-        struct cmsghdr  cmsghdr;
-        int fd[XCB_MAX_PASS_FD];
-    } fds;
+    char cmsgbuf[CMSG_SPACE(sizeof(int) * XCB_MAX_PASS_FD)];
     struct msghdr msg = {
         .msg_name = NULL,
         .msg_namelen = 0,
         .msg_iov = &iov,
         .msg_iovlen = 1,
-        .msg_control = &fds,
-        .msg_controllen = sizeof (struct cmsghdr) + sizeof(int) * (XCB_MAX_PASS_FD - c->in.in_fd.nfd),
+        .msg_control = cmsgbuf,
+        .msg_controllen = CMSG_SPACE(sizeof(int) * (XCB_MAX_PASS_FD - c->in.in_fd.nfd)),
     };
     n = recvmsg(c->fd, &msg, 0);
 
@@ -916,15 +913,12 @@ int _xcb_in_read(xcb_connection_t *c)
 #endif
     if(n > 0) {
 #if HAVE_SENDMSG
-        if (msg.msg_controllen > sizeof (struct cmsghdr))
-        {
-            if (fds.cmsghdr.cmsg_level == SOL_SOCKET &&
-                fds.cmsghdr.cmsg_type == SCM_RIGHTS)
-            {
-                int nfd = (msg.msg_controllen - sizeof (struct cmsghdr)) / sizeof (int);
-                memmove(&c->in.in_fd.fd[c->in.in_fd.nfd],
-                        fds.fd,
-                        nfd);
+        struct cmsghdr *hdr;
+
+        for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+            if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+                int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+                memcpy(&c->in.in_fd.fd[c->in.in_fd.nfd], CMSG_DATA(hdr), nfd * sizeof (int));
                 c->in.in_fd.nfd += nfd;
             }
         }
diff --git a/src/xcbint.h b/src/xcbint.h
index e122f2f..5c904fb 100644
--- a/src/xcbint.h
+++ b/src/xcbint.h
@@ -34,10 +34,6 @@
 #include "config.h"
 #endif
 
-#if HAVE_SENDMSG
-#include <sys/socket.h>
-#endif
-
 #ifdef GCC_HAS_VISIBILITY
 #pragma GCC visibility push(hidden)
 #endif
@@ -89,7 +85,6 @@ typedef void (*xcb_return_socket_func_t)(void *closure);
 #define XCB_MAX_PASS_FD	16
 
 typedef struct _xcb_fd {
-    struct cmsghdr cmsghdr;
     int fd[XCB_MAX_PASS_FD];
     int nfd;
     int ifd;


More information about the xcb-commit mailing list