1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
From 1766352059d0db67bff3f7dd0820563a30f54858 Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Thu, 18 Jun 2009 16:56:41 +1000
Subject: [PATCH] displayfd hack
---
dix/globals.c | 1 +
include/opaque.h | 1 +
os/connection.c | 72 ++++++++++++++++++++++++++++++++++++-----------------
os/utils.c | 11 ++++++++
4 files changed, 62 insertions(+), 23 deletions(-)
diff --git a/dix/globals.c b/dix/globals.c
index 907a5e8..c1e64d3 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -135,6 +135,7 @@ int defaultColorVisualClass = -1;
int monitorResolution = 0;
char *display;
+int displayfd;
char *ConnectionInfo;
CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;
diff --git a/include/opaque.h b/include/opaque.h
index fcc8c95..2a08e2d 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -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;
extern _X_EXPORT int defaultBackingStore;
extern _X_EXPORT Bool disableBackingStore;
diff --git a/os/connection.c b/os/connection.c
index 0c72b67..05d95c4 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -146,6 +146,7 @@ Bool NewOutputPending; /* not yet attempted to write some new output */
Bool AnyClientsWriteBlocked; /* true if some client blocked on write */
static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
+static char dynamic_display[7];
Bool PartialNetwork; /* continue even if unable to bind all addrs */
static Pid_t ParentProcess;
@@ -357,9 +358,23 @@ NotifyParentProcess(void)
kill (ParentProcess, SIGUSR1);
}
}
+ if (dynamic_display[0])
+ write(displayfd, dynamic_display, strlen(dynamic_display));
#endif
}
+static Bool
+TryCreateSocket(int num, int *partial)
+{
+ char port[20];
+
+ sprintf(port, "%d", num);
+
+ return _XSERVTransMakeAllCOTSServerListeners(port, partial,
+ &ListenTransCount,
+ &ListenTransConns);
+}
+
/*****************
* CreateWellKnownSockets
* At initialization, create the sockets to listen on for new clients.
@@ -370,7 +385,6 @@ CreateWellKnownSockets(void)
{
int i;
int partial;
- char port[20];
FD_ZERO(&AllSockets);
FD_ZERO(&AllClients);
@@ -385,32 +399,44 @@ CreateWellKnownSockets(void)
FD_ZERO (&WellKnownConnections);
- sprintf (port, "%d", atoi (display));
-
- if ((_XSERVTransMakeAllCOTSServerListeners (port, &partial,
- &ListenTransCount, &ListenTransConns) >= 0) &&
- (ListenTransCount >= 1))
+ if (display)
{
- if (!PartialNetwork && partial)
- {
- FatalError ("Failed to establish all listening sockets");
- }
- else
+ if (TryCreateSocket(atoi(display), &partial) &&
+ (ListenTransCount >= 1))
+ if (!PartialNetwork && partial)
+ FatalError ("Failed to establish all listening sockets");
+ }
+ else /* -displayfd */
+ {
+ Bool found = 0;
+ for (i = 0; i < 65535 - 1024; i++)
{
- ListenTransFds = xalloc (ListenTransCount * sizeof (int));
-
- for (i = 0; i < ListenTransCount; i++)
+ if (!TryCreateSocket(i, &partial) && !partial)
{
- int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
-
- ListenTransFds[i] = fd;
- FD_SET (fd, &WellKnownConnections);
-
- if (!_XSERVTransIsLocal (ListenTransConns[i]))
- {
- DefineSelf (fd);
- }
+ found = 1;
+ break;
}
+ else
+ CloseWellKnownConnections();
+ }
+ if (!found)
+ FatalError("Failed to find a socket to listen on");
+ sprintf(dynamic_display, "%d\n", i);
+ display = dynamic_display;
+ }
+
+ ListenTransFds = xalloc (ListenTransCount * sizeof (int));
+
+ for (i = 0; i < ListenTransCount; i++)
+ {
+ int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
+
+ ListenTransFds[i] = fd;
+ FD_SET (fd, &WellKnownConnections);
+
+ if (!_XSERVTransIsLocal (ListenTransConns[i]))
+ {
+ DefineSelf (fd);
}
}
diff --git a/os/utils.c b/os/utils.c
index 7bfdf8b..37a93b1 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -678,6 +678,17 @@ 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();
+ }
#ifdef DPMSExtension
else if ( strcmp( argv[i], "dpms") == 0)
/* ignored for compatibility */ ;
--
1.6.3.rc1.2.g0164.dirty
|