Handle -displayfd and an explicit display number sensibly

Handle -displayfd and an explicit display number sensibly, e.g. use the
explicitly specified display number, and write it to the displayfd

v2: displayfd might be 0, so use -1 as invalid value
v3: Rebase for addition of NoListenAll flag

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
This commit is contained in:
Jon TURNEY 2013-03-11 14:34:32 +00:00
parent a3730271d5
commit bc348bd2c4
4 changed files with 10 additions and 8 deletions

View File

@ -127,7 +127,8 @@ int defaultColorVisualClass = -1;
int monitorResolution = 0; int monitorResolution = 0;
const char *display; const char *display;
int displayfd; int displayfd = -1;
Bool explicit_display = FALSE;
char *ConnectionInfo; char *ConnectionInfo;
CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND; CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;

View File

@ -51,6 +51,7 @@ extern _X_EXPORT int defaultScreenSaverBlanking;
extern _X_EXPORT int defaultScreenSaverAllowExposures; extern _X_EXPORT int defaultScreenSaverAllowExposures;
extern _X_EXPORT const char *display; extern _X_EXPORT const char *display;
extern _X_EXPORT int displayfd; extern _X_EXPORT int displayfd;
extern _X_EXPORT Bool explicit_display;
extern _X_EXPORT int defaultBackingStore; extern _X_EXPORT int defaultBackingStore;
extern _X_EXPORT Bool disableBackingStore; extern _X_EXPORT Bool disableBackingStore;

View File

@ -352,8 +352,8 @@ void
NotifyParentProcess(void) NotifyParentProcess(void)
{ {
#if !defined(WIN32) #if !defined(WIN32)
if (dynamic_display[0]) { if (displayfd >= 0) {
write(displayfd, dynamic_display, strlen(dynamic_display)); write(displayfd, display, strlen(display));
write(displayfd, "\n", 1); write(displayfd, "\n", 1);
close(displayfd); close(displayfd);
} }
@ -405,18 +405,18 @@ CreateWellKnownSockets(void)
FD_ZERO(&WellKnownConnections); FD_ZERO(&WellKnownConnections);
/* 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. */
* option is used. */
if (NoListenAll) { if (NoListenAll) {
ListenTransCount = 0; ListenTransCount = 0;
} }
else if (display) { else if ((displayfd < 0) || explicit_display) {
if (TryCreateSocket(atoi(display), &partial) && if (TryCreateSocket(atoi(display), &partial) &&
ListenTransCount >= 1) ListenTransCount >= 1)
if (!PartialNetwork && partial) if (!PartialNetwork && partial)
FatalError ("Failed to establish all listening sockets"); FatalError ("Failed to establish all listening sockets");
} }
else { /* -displayfd */ else { /* -displayfd and no explicit display number */
Bool found = 0; Bool found = 0;
for (i = 0; i < 65535 - X_TCP_PORT; i++) { for (i = 0; i < 65535 - X_TCP_PORT; i++) {
if (TryCreateSocket(i, &partial) && !partial) { if (TryCreateSocket(i, &partial) && !partial) {

View File

@ -666,6 +666,7 @@ ProcessCommandLine(int argc, char *argv[])
else if (argv[i][0] == ':') { else if (argv[i][0] == ':') {
/* initialize display */ /* initialize display */
display = argv[i]; display = argv[i];
explicit_display = TRUE;
display++; display++;
if (!VerifyDisplayName(display)) { if (!VerifyDisplayName(display)) {
ErrorF("Bad display name: %s\n", display); ErrorF("Bad display name: %s\n", display);
@ -736,7 +737,6 @@ ProcessCommandLine(int argc, char *argv[])
else if (strcmp(argv[i], "-displayfd") == 0) { else if (strcmp(argv[i], "-displayfd") == 0) {
if (++i < argc) { if (++i < argc) {
displayfd = atoi(argv[i]); displayfd = atoi(argv[i]);
display = NULL;
#ifdef LOCK_SERVER #ifdef LOCK_SERVER
nolock = TRUE; nolock = TRUE;
#endif #endif