X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_in.c;h=95087be4e3a20adc38cc3421c672f05e9c7b1e08;hb=a1299eb2a210b5788a2b827b82a3d825caa1f201;hp=839f6157016f0b8fc3c1446ca0e367106d314b27;hpb=79019541e7c56ddfc3828b7bf96e6e5d3cf81c56;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_in.c b/src/xcb_in.c index 839f615..95087be 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -888,17 +888,17 @@ 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; + union { + struct cmsghdr cmsghdr; + char buf[CMSG_SPACE(XCB_MAX_PASS_FD * sizeof(int))]; + } cmsgbuf; 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.buf, + .msg_controllen = CMSG_SPACE(sizeof(int) * (XCB_MAX_PASS_FD - c->in.in_fd.nfd)), }; n = recvmsg(c->fd, &msg, 0); @@ -916,16 +916,15 @@ 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); - c->in.in_fd.nfd += nfd; + struct cmsghdr *hdr; + + if (msg.msg_controllen >= sizeof (struct cmsghdr)) { + 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; + } } } #endif