summaryrefslogtreecommitdiff
path: root/src/xcb_in.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-11-07 17:28:45 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-11-07 20:24:59 -0800
commit83f28ef8655acff746eab64eabe2e31f8cf0c892 (patch)
treefdf84e46857e3888cf8112d2c84f9cc94d055a51 /src/xcb_in.c
parentcca607409068ad0948e7283fb8d0465cabc51686 (diff)
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@keithp.com> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com> Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/xcb_in.c')
-rw-r--r--src/xcb_in.c24
1 files changed, 9 insertions, 15 deletions
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;
}
}