os: Add a mechanism to prevent creating any listen sockets

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 <krh@bitplanet.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Kristian Høgsberg 2014-03-19 14:03:13 -07:00 committed by Peter Hutterer
parent 62d584d631
commit 44fe1b8ea2
3 changed files with 10 additions and 4 deletions

View File

@ -74,5 +74,6 @@ extern _X_EXPORT Bool whiteRoot;
extern _X_EXPORT Bool bgNoneRoot; extern _X_EXPORT Bool bgNoneRoot;
extern _X_EXPORT Bool CoreDump; extern _X_EXPORT Bool CoreDump;
extern _X_EXPORT Bool NoListenAll;
#endif /* OPAQUE_H */ #endif /* OPAQUE_H */

View File

@ -138,6 +138,7 @@ fd_set OutputPending; /* clients with reply/event data ready to go */
int MaxClients = 0; int MaxClients = 0;
Bool NewOutputPending; /* not yet attempted to write some new output */ Bool NewOutputPending; /* not yet attempted to write some new output */
Bool AnyClientsWriteBlocked; /* true if some client blocked on write */ 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 */ static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
Bool RunFromSigStopParent; /* send SIGSTOP to our own process; Upstart (or 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 /* 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 * number if specified on the command line, or to NULL when the -displayfd
* option is used. */ * option is used. */
if (display) { if (NoListenAll) {
ListenTransCount = 0;
}
else if (display) {
if (TryCreateSocket(atoi(display), &partial) && if (TryCreateSocket(atoi(display), &partial) &&
ListenTransCount >= 1) ListenTransCount >= 1)
if (!PartialNetwork && partial) if (!PartialNetwork && partial)
@ -440,9 +444,10 @@ CreateWellKnownSockets(void)
DefineSelf (fd); DefineSelf (fd);
} }
if (!XFD_ANYSET(&WellKnownConnections)) if (!XFD_ANYSET(&WellKnownConnections) && !NoListenAll)
FatalError FatalError
("Cannot establish any listening sockets - Make sure an X server isn't already running"); ("Cannot establish any listening sockets - Make sure an X server isn't already running");
#if !defined(WIN32) #if !defined(WIN32)
OsSignal(SIGPIPE, SIG_IGN); OsSignal(SIGPIPE, SIG_IGN);
OsSignal(SIGHUP, AutoResetServer); OsSignal(SIGHUP, AutoResetServer);

View File

@ -270,7 +270,7 @@ LockServer(void)
int len; int len;
char port[20]; char port[20];
if (nolock) if (nolock || NoListenAll)
return; return;
/* /*
* Path names * Path names
@ -390,7 +390,7 @@ LockServer(void)
void void
UnlockServer(void) UnlockServer(void)
{ {
if (nolock) if (nolock || NoListenAll)
return; return;
if (!StillLocking) { if (!StillLocking) {