Blame SOURCES/0005-os-Add-a-function-to-create-a-client-for-an-fd.patch

d64d53
From efa65f0bd25889d34b690b91839a0b36d5864b39 Mon Sep 17 00:00:00 2001
70130e
From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= <krh@bitplanet.net>
70130e
Date: Tue, 21 Jun 2011 21:28:31 -0400
d64d53
Subject: [PATCH 05/38] os: Add a function to create a client for an fd
70130e
70130e
---
70130e
 include/opaque.h |  1 +
70130e
 include/os.h     |  5 +++--
70130e
 os/connection.c  | 32 +++++++++++++++++++++++++++++---
70130e
 os/utils.c       |  6 +++++-
70130e
 4 files changed, 38 insertions(+), 6 deletions(-)
70130e
70130e
diff --git a/include/opaque.h b/include/opaque.h
70130e
index b76ab6e..8ad9af0 100644
70130e
--- a/include/opaque.h
70130e
+++ b/include/opaque.h
70130e
@@ -74,5 +74,6 @@ extern _X_EXPORT Bool whiteRoot;
70130e
 extern _X_EXPORT Bool bgNoneRoot;
70130e
 
70130e
 extern _X_EXPORT Bool CoreDump;
70130e
+extern _X_EXPORT Bool NoListenAll;
70130e
 
70130e
 #endif                          /* OPAQUE_H */
70130e
diff --git a/include/os.h b/include/os.h
d64d53
index 9b67294..c36d09a 100644
70130e
--- a/include/os.h
70130e
+++ b/include/os.h
d64d53
@@ -166,8 +166,9 @@ extern _X_EXPORT void MakeClientGrabImpervious(ClientPtr /*client */ );
70130e
 
70130e
 extern _X_EXPORT void MakeClientGrabPervious(ClientPtr /*client */ );
70130e
 
70130e
-#ifdef XQUARTZ
70130e
-extern void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
70130e
+#if defined(XQUARTZ) || defined(XORG_WAYLAND)
70130e
+extern _X_EXPORT void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
70130e
+extern _X_EXPORT void AddClientOnOpenFD(int /* fd */ );
70130e
 #endif
70130e
 
70130e
 extern _X_EXPORT CARD32 GetTimeInMillis(void);
70130e
diff --git a/os/connection.c b/os/connection.c
70130e
index 162e1d9..a95e7da 100644
70130e
--- a/os/connection.c
70130e
+++ b/os/connection.c
70130e
@@ -64,6 +64,7 @@ SOFTWARE.
70130e
 #include <dix-config.h>
70130e
 #endif
70130e
 
70130e
+#include <xorg-server.h>
70130e
 #ifdef WIN32
70130e
 #include <X11/Xwinsock.h>
70130e
 #endif
70130e
@@ -138,6 +139,7 @@ fd_set OutputPending;           /* clients with reply/event data ready to go */
70130e
 int MaxClients = 0;
70130e
 Bool NewOutputPending;          /* not yet attempted to write some new output */
70130e
 Bool AnyClientsWriteBlocked;    /* true if some client blocked on write */
70130e
+Bool NoListenAll;               /* Don't establish any listening sockets */
70130e
 
70130e
 static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
70130e
 Bool RunFromSigStopParent;      /* send SIGSTOP to our own process; Upstart (or
70130e
@@ -406,7 +408,10 @@ CreateWellKnownSockets(void)
70130e
     /* display is initialized to "0" by main(). It is then set to the display
70130e
      * number if specified on the command line, or to NULL when the -displayfd
70130e
      * option is used. */
70130e
-    if (display) {
70130e
+    if (NoListenAll) {
70130e
+        ListenTransCount = 0;
70130e
+    }
70130e
+    else if (display) {
70130e
         if (TryCreateSocket(atoi(display), &partial) &&
70130e
             ListenTransCount >= 1)
70130e
             if (!PartialNetwork && partial)
70130e
@@ -440,9 +445,10 @@ CreateWellKnownSockets(void)
70130e
             DefineSelf (fd);
70130e
     }
70130e
 
70130e
-    if (!XFD_ANYSET(&WellKnownConnections))
70130e
+    if (!XFD_ANYSET(&WellKnownConnections) && !NoListenAll)
70130e
         FatalError
70130e
             ("Cannot establish any listening sockets - Make sure an X server isn't already running");
70130e
+
70130e
 #if !defined(WIN32)
70130e
     OsSignal(SIGPIPE, SIG_IGN);
70130e
     OsSignal(SIGHUP, AutoResetServer);
70130e
@@ -1253,7 +1259,7 @@ MakeClientGrabPervious(ClientPtr client)
70130e
     }
70130e
 }
70130e
 
70130e
-#ifdef XQUARTZ
70130e
+#if defined(XQUARTZ) || defined(XORG_WAYLAND)
70130e
 /* Add a fd (from launchd) to our listeners */
70130e
 void
70130e
 ListenOnOpenFD(int fd, int noxauth)
70130e
@@ -1309,4 +1315,24 @@ ListenOnOpenFD(int fd, int noxauth)
70130e
 #endif
70130e
 }
70130e
 
70130e
+/* based on TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) */
70130e
+void
70130e
+AddClientOnOpenFD(int fd)
70130e
+{
70130e
+    XtransConnInfo ciptr;
70130e
+    CARD32 connect_time;
70130e
+
70130e
+    ciptr = _XSERVTransReopenCOTSServer(5, fd, "@anonymous");
70130e
+
70130e
+    _XSERVTransSetOption(ciptr, TRANS_NONBLOCKING, 1);
70130e
+    ciptr->flags |= TRANS_NOXAUTH;
70130e
+
70130e
+    connect_time = GetTimeInMillis();
70130e
+
70130e
+    if (!AllocNewConnection(ciptr, fd, connect_time)) {
70130e
+        fprintf(stderr, "failed to create client for wayland server\n");
70130e
+        return;
70130e
+    }
70130e
+}
70130e
+
70130e
 #endif
70130e
diff --git a/os/utils.c b/os/utils.c
d64d53
index 608ee6a..a0cf951 100644
70130e
--- a/os/utils.c
70130e
+++ b/os/utils.c
70130e
@@ -805,7 +805,11 @@ ProcessCommandLine(int argc, char *argv[])
70130e
 #endif
70130e
         else if (strcmp(argv[i], "-nolisten") == 0) {
70130e
             if (++i < argc) {
70130e
-                if (_XSERVTransNoListen(argv[i]))
70130e
+                if (strcmp(argv[i], "all") == 0) {
70130e
+                    NoListenAll = TRUE;
70130e
+                    nolock = TRUE;
70130e
+                }
70130e
+                else if (_XSERVTransNoListen(argv[i]))
70130e
                     ErrorF("Failed to disable listen for %s transport",
70130e
                            argv[i]);
70130e
             }
70130e
-- 
d64d53
1.8.4.2
70130e