[PATCH 06/10] os: Add a function to create a client for an fd
Adam Jackson
ajax at redhat.com
Thu Oct 17 09:34:34 PDT 2013
From: Kristian Høgsberg <krh at bitplanet.net>
Reviewed-by: Adam Jackson <ajax at redhat.com>
---
include/opaque.h | 1 +
include/os.h | 6 +++---
os/connection.c | 30 ++++++++++++++++++++++++++----
os/utils.c | 6 +++++-
4 files changed, 35 insertions(+), 8 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/include/os.h b/include/os.h
index c7108a5..5d845b0 100644
--- a/include/os.h
+++ b/include/os.h
@@ -160,9 +160,9 @@ extern _X_EXPORT void MakeClientGrabImpervious(ClientPtr /*client */ );
extern _X_EXPORT void MakeClientGrabPervious(ClientPtr /*client */ );
-#ifdef XQUARTZ
-extern void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
-#endif
+extern _X_EXPORT void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
+
+extern _X_EXPORT void AddClientOnOpenFD(int /* fd */ );
extern _X_EXPORT CARD32 GetTimeInMillis(void);
diff --git a/os/connection.c b/os/connection.c
index 6cd8bcf..65ca01b 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);
@@ -1253,7 +1258,6 @@ MakeClientGrabPervious(ClientPtr client)
}
}
-#ifdef XQUARTZ
/* Add a fd (from launchd) to our listeners */
void
ListenOnOpenFD(int fd, int noxauth)
@@ -1309,4 +1313,22 @@ ListenOnOpenFD(int fd, int noxauth)
#endif
}
-#endif
+/* based on TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) */
+void
+AddClientOnOpenFD(int fd)
+{
+ XtransConnInfo ciptr;
+ CARD32 connect_time;
+
+ ciptr = _XSERVTransReopenCOTSServer(5, fd, "@anonymous");
+
+ _XSERVTransSetOption(ciptr, TRANS_NONBLOCKING, 1);
+ ciptr->flags |= TRANS_NOXAUTH;
+
+ connect_time = GetTimeInMillis();
+
+ if (!AllocNewConnection(ciptr, fd, connect_time)) {
+ fprintf(stderr, "failed to create client for wayland server\n");
+ return;
+ }
+}
diff --git a/os/utils.c b/os/utils.c
index 97c3125..3e9f525 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -778,7 +778,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.8.3.1
More information about the xorg-devel
mailing list