[Xcb] [PATCH 4/8] Add xcb_send_fd API

Uli Schlachter psychon at znc.in
Thu Nov 7 05:47:51 PST 2013


On 07.11.2013 13:24, Keith Packard wrote:
> Uli Schlachter <psychon at znc.in> writes:
>
>> Having thought about this some more in the shower, I would suggest to turn
>> xcb_send_fd() into a private _send_fd() and instead add
>> xcb_send_request_with_fds() (or something like that).
>
> This isn't necessary; as I explained, the X server just holds onto FDs
> that the client sends until a request consumes them. Yes, it has to deal
> with clients sending unexpected FDs, there's nothing special about this.

Ok, but then xcb needs to do the same (see below).

[...]
>> - Does the new sendmsg() call work correctly on non-unix sockets when no FDs are
>> transmitted?
>
> You'll note that sendmsg is *not* called when we have no file
> descriptors to send.

Ah, sorry, I did indeed miss that part.

>> - Should we have some API to test if sending FDs works at all or if xcb just
>> ignores the FDs?
>
> I'm not entirely sure how you'd do that without actually trying to send
> an FD, given that XCB can be handed a pre-connected file descriptor.
>
>> - What happens with partial reads? Let's say we send 4KiB of requests to the
>> server in one sendmsg() call and the last request has FDs attached. For whatever
>> reason, the server only reads 2KiB of data from the socket. Will the FDs be
>> handled correctly in this case? What if the FDs are for the first request
>> instead of the last one?
>
> The FDs are effectively attached to the first byte of the write; read
> that bytes and you get all of the FDs sent there. So, if you perform
> a 4kB write with 10 file descriptors, and read only 2kB, then you'll get
> all 10 file descriptors as you've read the relevant byte.

Ok, seems like the server handles this correctly then.

However, now I wonder about patch 5/8 "Add support for receiving fds" which does 
not do this.

If I understood the code correctly, _xcb_in_read() will close the connection 
with an error if a partial read happens and thus we get FDs before the 
corresponding event/reply.

In other words, the server handles partial reads correctly, xcb doesn't

>> Oh and I just noticed:
>> If HAVE_SENDMSG is not defined, shouldn't xcb_send_fd() close() the FD
>> that it gets?
>
> The X server won't advertise any requests which receive or send file
> descriptors on a system which doesn't support SENDMSG, so I'm not sure
> how interesting the precise semantics of this error case are. And, I
> assume the BSD people will shortly figure out how to make this work on
> their operating systems, which means that pretty much anything with
> local applications will have working xcb FD passing.

I've seen lots of code which just uses an extension without checking for its 
availability. I am sure people will be able to get this wrong, too. At least I 
hope that this would then cause an error from the server and thus gets noticed...

Anyway, I guess I ran out of doubts for this patch (and now have new doubts 
about patch 5/8), so:

Reviewed-By: Uli Schlachter <psychon at znc.in>

Uli


More information about the xorg-devel mailing list