From 215f3d2e0f2a4ef6fc2f2c08fb991e1f00b747c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 19 Mar 2014 20:46:41 -0700 Subject: [PATCH] os: Add AddClientOnOpenFD() to create a new client for an file descriptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the Xwayland server is socket-activated, we need to connect and initialize the window manager before the activating client gets to proceed with connecting. We do this by passing a socket file descriptor for the window manager connection to the Xwayland server, which then uses this new function to set it up as an X client. Signed-off-by: Kristian Høgsberg Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- include/os.h | 2 ++ os/connection.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/os.h b/include/os.h index 90229e672..d26e399b6 100644 --- a/include/os.h +++ b/include/os.h @@ -168,6 +168,8 @@ extern _X_EXPORT void MakeClientGrabPervious(ClientPtr /*client */ ); extern _X_EXPORT void ListenOnOpenFD(int /* fd */ , int /* noxauth */ ); +extern _X_EXPORT Bool AddClientOnOpenFD(int /* fd */ ); + extern _X_EXPORT CARD32 GetTimeInMillis(void); extern _X_EXPORT CARD64 GetTimeInMicros(void); diff --git a/os/connection.c b/os/connection.c index b50f9e914..b3640b8e4 100644 --- a/os/connection.c +++ b/os/connection.c @@ -1312,3 +1312,30 @@ ListenOnOpenFD(int fd, int noxauth) XdmcpReset(); #endif } + +/* based on TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) */ +Bool +AddClientOnOpenFD(int fd) +{ + XtransConnInfo ciptr; + CARD32 connect_time; + char port[20]; + + snprintf(port, sizeof(port), ":%d", atoi(display)); + ciptr = _XSERVTransReopenCOTSServer(5, fd, port); + if (ciptr == NULL) + return FALSE; + + _XSERVTransSetOption(ciptr, TRANS_NONBLOCKING, 1); + ciptr->flags |= TRANS_NOXAUTH; + + connect_time = GetTimeInMillis(); + + if (!AllocNewConnection(ciptr, fd, connect_time)) { + ErrorConnMax(ciptr); + _XSERVTransClose(ciptr); + return FALSE; + } + + return TRUE; +}