2012-05-14 07:43:18 +00:00
|
|
|
From 247319fe3750671cd962df2c12548affb0351775 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Chase Douglas <chase.douglas@canonical.com>
|
|
|
|
Date: Wed, 4 Apr 2012 15:29:42 -0700
|
|
|
|
Subject: [PATCH 3/7] os: Add -displayfd option
|
2009-04-06 20:09:11 +00:00
|
|
|
|
2012-05-14 07:43:18 +00:00
|
|
|
This option specifies a file descriptor in the launching process. X
|
|
|
|
will scan for an available display number and write that number back to
|
|
|
|
the launching process, at the same time as SIGUSR1 generation. This
|
|
|
|
means display managers don't need to guess at available display numbers.
|
|
|
|
As a consequence, if X fails to start when using -displayfd, it's not
|
|
|
|
because the display was in use, so there's no point in retrying the X
|
|
|
|
launch on a higher display number.
|
|
|
|
|
|
|
|
Signed-off-by: Adam Jackson <ajax@redhat.com>
|
|
|
|
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
|
|
|
|
Reviewed-by: Julien Cristau <jcristau@debian.org>
|
|
|
|
Tested-by: Julien Cristau <jcristau@debian.org>
|
|
|
|
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
|
|
|
|
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
|
2009-04-06 20:09:11 +00:00
|
|
|
---
|
|
|
|
dix/globals.c | 1 +
|
|
|
|
include/opaque.h | 1 +
|
2012-05-14 07:43:18 +00:00
|
|
|
man/Xserver.man | 7 ++++++
|
|
|
|
os/connection.c | 68 ++++++++++++++++++++++++++++++++++++++----------------
|
|
|
|
os/utils.c | 9 ++++++++
|
|
|
|
5 files changed, 66 insertions(+), 20 deletions(-)
|
2009-04-06 20:09:11 +00:00
|
|
|
|
|
|
|
diff --git a/dix/globals.c b/dix/globals.c
|
2012-05-14 07:43:18 +00:00
|
|
|
index c0cae15..db113ca 100644
|
2009-04-06 20:09:11 +00:00
|
|
|
--- a/dix/globals.c
|
|
|
|
+++ b/dix/globals.c
|
2012-05-14 07:43:18 +00:00
|
|
|
@@ -128,6 +128,7 @@ int defaultColorVisualClass = -1;
|
2009-06-19 07:03:32 +00:00
|
|
|
int monitorResolution = 0;
|
2009-04-06 20:09:11 +00:00
|
|
|
|
2009-06-19 07:03:32 +00:00
|
|
|
char *display;
|
2009-04-06 20:09:11 +00:00
|
|
|
+int displayfd;
|
|
|
|
char *ConnectionInfo;
|
|
|
|
|
|
|
|
CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;
|
|
|
|
diff --git a/include/opaque.h b/include/opaque.h
|
2012-05-14 07:43:18 +00:00
|
|
|
index 9ca408a..b76ab6e 100644
|
2009-04-06 20:09:11 +00:00
|
|
|
--- a/include/opaque.h
|
|
|
|
+++ b/include/opaque.h
|
2009-06-19 07:03:32 +00:00
|
|
|
@@ -50,6 +50,7 @@ extern _X_EXPORT int ScreenSaverAllowExposures;
|
|
|
|
extern _X_EXPORT int defaultScreenSaverBlanking;
|
|
|
|
extern _X_EXPORT int defaultScreenSaverAllowExposures;
|
|
|
|
extern _X_EXPORT char *display;
|
|
|
|
+extern _X_EXPORT int displayfd;
|
2009-04-06 20:09:11 +00:00
|
|
|
|
2009-06-19 07:03:32 +00:00
|
|
|
extern _X_EXPORT int defaultBackingStore;
|
|
|
|
extern _X_EXPORT Bool disableBackingStore;
|
2012-05-14 07:43:18 +00:00
|
|
|
diff --git a/man/Xserver.man b/man/Xserver.man
|
|
|
|
index 0cd9b94..8d243d6 100644
|
|
|
|
--- a/man/Xserver.man
|
|
|
|
+++ b/man/Xserver.man
|
|
|
|
@@ -127,6 +127,13 @@ Not obeyed by all servers.
|
|
|
|
.B \-core
|
|
|
|
causes the server to generate a core dump on fatal errors.
|
|
|
|
.TP 8
|
|
|
|
+.B \-displayfd \fIfd\fP
|
|
|
|
+specifies a file descriptor in the launching process. Rather than specify
|
|
|
|
+a display number, the X server will attempt to listen on successively higher
|
|
|
|
+display numbers, and upon finding a free one, will write the port number back
|
|
|
|
+on this file descriptor as a newline-terminated string. The \-pn option is
|
|
|
|
+ignored when using \-displayfd.
|
|
|
|
+.TP 8
|
|
|
|
.B \-deferglyphs \fIwhichfonts\fP
|
|
|
|
specifies the types of fonts for which the server should attempt to use
|
|
|
|
deferred glyph loading. \fIwhichfonts\fP can be all (all fonts),
|
2009-04-06 20:09:11 +00:00
|
|
|
diff --git a/os/connection.c b/os/connection.c
|
2012-05-14 07:43:18 +00:00
|
|
|
index 1099752..039942f 100644
|
2009-04-06 20:09:11 +00:00
|
|
|
--- a/os/connection.c
|
|
|
|
+++ b/os/connection.c
|
2012-05-14 07:43:18 +00:00
|
|
|
@@ -142,6 +142,7 @@ Bool AnyClientsWriteBlocked; /* true if some client blocked on write */
|
|
|
|
static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
|
|
|
|
Bool RunFromSigStopParent; /* send SIGSTOP to our own process; Upstart (or
|
|
|
|
equivalent) will send SIGCONT back. */
|
|
|
|
+static char dynamic_display[7]; /* display name */
|
|
|
|
Bool PartialNetwork; /* continue even if unable to bind all addrs */
|
2009-04-06 20:09:11 +00:00
|
|
|
static Pid_t ParentProcess;
|
|
|
|
|
2012-05-14 07:43:18 +00:00
|
|
|
@@ -350,6 +351,10 @@ void
|
|
|
|
NotifyParentProcess(void)
|
|
|
|
{
|
|
|
|
#if !defined(WIN32)
|
|
|
|
+ if (dynamic_display[0]) {
|
|
|
|
+ write(displayfd, dynamic_display, strlen(dynamic_display));
|
|
|
|
+ close(displayfd);
|
|
|
|
+ }
|
|
|
|
if (RunFromSmartParent) {
|
|
|
|
if (ParentProcess > 1) {
|
|
|
|
kill(ParentProcess, SIGUSR1);
|
|
|
|
@@ -360,6 +365,18 @@ NotifyParentProcess(void)
|
2009-04-06 20:09:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
+static Bool
|
|
|
|
+TryCreateSocket(int num, int *partial)
|
|
|
|
+{
|
|
|
|
+ char port[20];
|
|
|
|
+
|
2012-05-14 07:43:18 +00:00
|
|
|
+ snprintf(port, sizeof(port), "%d", num);
|
2009-04-06 20:09:11 +00:00
|
|
|
+
|
2012-05-14 07:43:18 +00:00
|
|
|
+ return (_XSERVTransMakeAllCOTSServerListeners(port, partial,
|
|
|
|
+ &ListenTransCount,
|
|
|
|
+ &ListenTransConns) >= 0);
|
2009-04-06 20:09:11 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
/*****************
|
|
|
|
* CreateWellKnownSockets
|
|
|
|
* At initialization, create the sockets to listen on for new clients.
|
2012-05-14 07:43:18 +00:00
|
|
|
@@ -370,7 +387,6 @@ CreateWellKnownSockets(void)
|
2009-04-06 20:09:11 +00:00
|
|
|
{
|
2012-05-14 07:43:18 +00:00
|
|
|
int i;
|
|
|
|
int partial;
|
|
|
|
- char port[20];
|
2009-04-06 20:09:11 +00:00
|
|
|
|
|
|
|
FD_ZERO(&AllSockets);
|
|
|
|
FD_ZERO(&AllClients);
|
2012-05-14 07:43:18 +00:00
|
|
|
@@ -386,29 +402,41 @@ CreateWellKnownSockets(void)
|
2009-04-06 20:09:11 +00:00
|
|
|
|
2012-05-14 07:43:18 +00:00
|
|
|
FD_ZERO(&WellKnownConnections);
|
2009-04-06 20:09:11 +00:00
|
|
|
|
2012-05-14 07:43:18 +00:00
|
|
|
- snprintf(port, sizeof(port), "%d", atoi(display));
|
2009-04-06 20:09:11 +00:00
|
|
|
-
|
2012-05-14 07:43:18 +00:00
|
|
|
- if ((_XSERVTransMakeAllCOTSServerListeners(port, &partial,
|
|
|
|
- &ListenTransCount,
|
|
|
|
- &ListenTransConns) >= 0) &&
|
|
|
|
- (ListenTransCount >= 1)) {
|
|
|
|
- if (!PartialNetwork && partial) {
|
|
|
|
- FatalError("Failed to establish all listening sockets");
|
|
|
|
+ /* 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 (TryCreateSocket(atoi(display), &partial) &&
|
|
|
|
+ ListenTransCount >= 1)
|
|
|
|
+ if (!PartialNetwork && partial)
|
|
|
|
+ FatalError ("Failed to establish all listening sockets");
|
2009-04-06 20:09:11 +00:00
|
|
|
+ }
|
2012-05-14 07:43:18 +00:00
|
|
|
+ else { /* -displayfd */
|
|
|
|
+ Bool found = 0;
|
|
|
|
+ for (i = 0; i < 65535 - X_TCP_PORT; i++) {
|
|
|
|
+ if (TryCreateSocket(i, &partial) && !partial) {
|
|
|
|
+ found = 1;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ CloseWellKnownConnections();
|
|
|
|
}
|
|
|
|
- else {
|
|
|
|
- ListenTransFds = malloc(ListenTransCount * sizeof(int));
|
|
|
|
+ if (!found)
|
|
|
|
+ FatalError("Failed to find a socket to listen on");
|
|
|
|
+ snprintf(dynamic_display, sizeof(dynamic_display), "%d", i);
|
|
|
|
+ display = dynamic_display;
|
2009-04-06 20:09:11 +00:00
|
|
|
+ }
|
2012-05-14 07:43:18 +00:00
|
|
|
|
|
|
|
- for (i = 0; i < ListenTransCount; i++) {
|
|
|
|
- int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
|
|
|
+ ListenTransFds = malloc(ListenTransCount * sizeof (int));
|
|
|
|
|
|
|
|
- ListenTransFds[i] = fd;
|
|
|
|
- FD_SET(fd, &WellKnownConnections);
|
|
|
|
+ for (i = 0; i < ListenTransCount; i++) {
|
|
|
|
+ int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
|
|
|
|
|
|
|
- if (!_XSERVTransIsLocal(ListenTransConns[i])) {
|
|
|
|
- DefineSelf(fd);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
+ ListenTransFds[i] = fd;
|
|
|
|
+ FD_SET(fd, &WellKnownConnections);
|
2009-04-06 20:09:11 +00:00
|
|
|
+
|
2012-05-14 07:43:18 +00:00
|
|
|
+ if (!_XSERVTransIsLocal(ListenTransConns[i]))
|
|
|
|
+ DefineSelf (fd);
|
2009-04-06 20:09:11 +00:00
|
|
|
}
|
|
|
|
|
2012-05-14 07:43:18 +00:00
|
|
|
if (!XFD_ANYSET(&WellKnownConnections))
|
2009-04-06 20:09:11 +00:00
|
|
|
diff --git a/os/utils.c b/os/utils.c
|
2012-05-14 07:43:18 +00:00
|
|
|
index 30592d2..3a1ef93 100644
|
2009-04-06 20:09:11 +00:00
|
|
|
--- a/os/utils.c
|
|
|
|
+++ b/os/utils.c
|
2012-05-14 07:43:18 +00:00
|
|
|
@@ -659,6 +659,15 @@ ProcessCommandLine(int argc, char *argv[])
|
|
|
|
else
|
|
|
|
UseMsg();
|
|
|
|
}
|
|
|
|
+ else if (strcmp(argv[i], "-displayfd") == 0) {
|
|
|
|
+ if (++i < argc) {
|
|
|
|
+ displayfd = atoi(argv[i]);
|
|
|
|
+ display = NULL;
|
|
|
|
+ nolock = TRUE;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ UseMsg();
|
|
|
|
+ }
|
2009-04-06 20:09:11 +00:00
|
|
|
#ifdef DPMSExtension
|
2012-05-14 07:43:18 +00:00
|
|
|
else if (strcmp(argv[i], "dpms") == 0)
|
|
|
|
/* ignored for compatibility */ ;
|
2009-04-06 20:09:11 +00:00
|
|
|
--
|
2012-05-14 07:43:18 +00:00
|
|
|
1.7.10.1
|
2009-04-06 20:09:11 +00:00
|
|
|
|