[PATCH 4/7] Add support for receiving fds in replies

Mark Kettenis mark.kettenis at xs4all.nl
Wed Nov 6 04:42:45 PST 2013


> From: Keith Packard <keithp at keithp.com>
> Date: Tue,  5 Nov 2013 16:41:24 -0800
> 
> Requests signal which replies will have fds, and the replies report
> how many fds they expect in byte 1.

Same comment about not using the CMSG_ API properly.  Error handling
of the recvmsg(2) call isn't adequate either.  Probably should
consider MSG_TRUNC and MSG_CTRUNC as fatal errors and clean up any
file descriptors that you did receive like we discussed for libxtrans.

I don't see a mechanism to "flush out" file descriptors that were
received but not consumed, i.e. if a nasty server sent you some file
descriptors together with a request for which you didn't expect any.
Am I missing something?

Also:

> diff --git a/src/xcb_in.c b/src/xcb_in.c
> index ac4d284..f9a10e7 100644
> --- a/src/xcb_in.c
> +++ b/src/xcb_in.c
> @@ -91,11 +91,26 @@ static void remove_finished_readers(reader_list **prev_reader, uint64_t complete
>      }
>  }
>  
> +#if HAVE_SENDMSG
> +static int read_fds(xcb_connection_t *c, int *fds, int nfd)
> +{
> +    int *ifds = &c->in.in_fd.fd[c->in.in_fd.ifd];
> +    int infd = c->in.in_fd.nfd - c->in.in_fd.ifd;
> +
> +    if (nfd > infd)
> +        return -1;
> +    memcpy(fds, ifds, nfd * sizeof (int));
> +    c->in.in_fd.ifd += nfd;
> +    return nfd * sizeof (int);

wouldn't it make more sense to simply return nfd here?


More information about the xorg-devel mailing list