[xcb/libxcb] Don't close file descriptors received before associated replies

Submitted by Keith Packard on April 3, 2018, 11:34 p.m.

Details

Message ID 20180403233419.15672-1-keithp@keithp.com
State New
Headers show
Series "Don't close file descriptors received before associated replies" ( rev: 1 ) in X.org

Not browsing as part of any series.

Commit Message

Keith Packard April 3, 2018, 11:34 p.m.
The X server may send reply file descriptors at any point before the
reply itself as the buffering of fds in the socket is separate from
reply data. Instead of closing those received early, leave them around
in xcb and await the receipt of the associated reply.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 src/xcb_in.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/xcb_in.c b/src/xcb_in.c
index 73209e0..fc58622 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -1025,17 +1025,11 @@  int _xcb_in_read(xcb_connection_t *c)
                 c->in.in_fd.nfd * sizeof (int));
         c->in.in_fd.ifd = 0;
 
-        /* If we have any left-over file descriptors after emptying
-         * the input buffer, then the server sent some that we weren't
-         * expecting.  Close them and mark the connection as broken;
+        /* Leave any remaining file descriptors around; the associated
+         * replies will be along shortly to pick them up. This way,
+         * the X server just needs to make sure the fds are sent no
+         * later than the reply, but can be sent at any earlier time.
          */
-        if (c->in.queue_len == 0 && c->in.in_fd.nfd != 0) {
-            int i;
-            for (i = 0; i < c->in.in_fd.nfd; i++)
-                close(c->in.in_fd.fd[i]);
-            _xcb_conn_shutdown(c, XCB_CONN_CLOSED_FDPASSING_FAILED);
-            return 0;
-        }
     }
 #endif
 #ifndef _WIN32