[PATCH 4/6] os: Add AddClientOnOpenFD() to create a new client for an file descriptor

Kristian Høgsberg krh at bitplanet.net
Tue Mar 25 14:57:15 PDT 2014


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 <krh at bitplanet.net>
Reviewed-by: Daniel Stone <daniel at fooishbar.org>
---
 include/os.h    |  2 ++
 os/connection.c | 27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/os.h b/include/os.h
index 90229e6..d26e399 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 b50f9e9..b3640b8 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;
+}
-- 
1.9.0



More information about the xorg-devel mailing list