From 44fe1b8ea284df6bbaef67e246016d104665b2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 19 Mar 2014 14:03:13 -0700 Subject: [PATCH] os: Add a mechanism to prevent creating any listen sockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A socket-activated server will receive its listening sockets from the parent process and should not create its own sockets. This patch introduces a NoListen flag that can be set by a DDX to prevent the server from creating the sockets. When NoListen is enabled, we also disable the server lock checking, since the parent process is responsible for checking the lock before picking the display name and creating the sockets. Signed-off-by: Kristian Høgsberg Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- include/opaque.h | 1 + os/connection.c | 9 +++++++-- os/utils.c | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/opaque.h b/include/opaque.h index 73d40c3452..7ec1d850fb 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 400c5425d7..b50f9e914f 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 @@ -406,7 +407,10 @@ CreateWellKnownSockets(void) /* display is initialized to "0" by main(). It is then set to the display * number if specified on the command line, or to NULL when the -displayfd * option is used. */ - if (display) { + if (NoListenAll) { + ListenTransCount = 0; + } + else if (display) { if (TryCreateSocket(atoi(display), &partial) && ListenTransCount >= 1) if (!PartialNetwork && 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 497779b52e..c513968ad6 100644 --- a/os/utils.c +++ b/os/utils.c @@ -270,7 +270,7 @@ LockServer(void) int len; char port[20]; - if (nolock) + if (nolock || NoListenAll) return; /* * Path names @@ -390,7 +390,7 @@ LockServer(void) void UnlockServer(void) { - if (nolock) + if (nolock || NoListenAll) return; if (!StillLocking) {