[PATCH 5/6] Add NoListenAll to disable listening on all sockets

Daniel Stone daniel at fooishbar.org
Tue Nov 6 22:58:22 PST 2012


From: Kristian Høgsberg <krh at redhat.com>

Useful for fd passing, including under XWayland where we receive our
listening socket from the compositor.

Signed-off-by: Kristian Høgsberg <krh at redhat.com>
---
 include/opaque.h |    1 +
 os/connection.c  |    7 ++++++-
 os/utils.c       |    6 +++++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/opaque.h b/include/opaque.h
index b76ab6e..8ad9af0 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -74,5 +74,6 @@ extern _X_EXPORT Bool whiteRoot;
 extern _X_EXPORT Bool bgNoneRoot;
 
 extern _X_EXPORT Bool CoreDump;
+extern _X_EXPORT Bool NoListenAll;
 
 #endif                          /* OPAQUE_H */
diff --git a/os/connection.c b/os/connection.c
index 6cd8bcf..91e3b13 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -138,6 +138,7 @@ fd_set OutputPending;           /* clients with reply/event data ready to go */
 int MaxClients = 0;
 Bool NewOutputPending;          /* not yet attempted to write some new output */
 Bool AnyClientsWriteBlocked;    /* true if some client blocked on write */
+Bool NoListenAll;               /* Don't establish any listening sockets */
 
 static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
 Bool RunFromSigStopParent;      /* send SIGSTOP to our own process; Upstart (or
@@ -371,6 +372,9 @@ TryCreateSocket(int num, int *partial)
 {
     char port[20];
 
+    if (NoListenAll)
+        return TRUE;
+
     snprintf(port, sizeof(port), "%d", num);
 
     return (_XSERVTransMakeAllCOTSServerListeners(port, partial,
@@ -440,9 +444,10 @@ CreateWellKnownSockets(void)
             DefineSelf (fd);
     }
 
-    if (!XFD_ANYSET(&WellKnownConnections))
+    if (!XFD_ANYSET(&WellKnownConnections) && !NoListenAll)
         FatalError
             ("Cannot establish any listening sockets - Make sure an X server isn't already running");
+
 #if !defined(WIN32)
     OsSignal(SIGPIPE, SIG_IGN);
     OsSignal(SIGHUP, AutoResetServer);
diff --git a/os/utils.c b/os/utils.c
index 3c520ad..1c34cd3 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -775,7 +775,11 @@ ProcessCommandLine(int argc, char *argv[])
 #endif
         else if (strcmp(argv[i], "-nolisten") == 0) {
             if (++i < argc) {
-                if (_XSERVTransNoListen(argv[i]))
+                if (strcmp(argv[i], "all") == 0) {
+                    NoListenAll = TRUE;
+                    nolock = TRUE;
+                }
+                else if (_XSERVTransNoListen(argv[i]))
                     ErrorF("Failed to disable listen for %s transport",
                            argv[i]);
             }
-- 
1.7.10.4



More information about the xorg-devel mailing list