[PATCH xserver] os: add an optional offset to -displayfd parameter

Bernhard Miklautz bernhard.miklautz at thincast.com
Mon Jun 13 15:06:10 UTC 2016


The displayfd option is very handy and useful. However, in some environments
where many servers are running (for example in an automated build
environment using Xvfb) it is often desirable to be able to specify
an initial offset for the display search.

For example if it is known that the first 100 displays are
already taken it isn't currently possible to start at 101 therefore
each subsequent Xvfb launch would re-try all displays from :0 to :100.

This patch adds an optional offset option to the displayfd parameter
that allows it to specify the initial display number to start the search
from. The format is:

-displayfd fd[:<offset>]

The patch also updates the help as well as the Xserver man page accordingly.

Signed-off-by: Bernhard Miklautz <bernhard.miklautz at thincast.com>
---
 dix/globals.c    | 1 +
 include/opaque.h | 1 +
 man/Xserver.man  | 7 ++++---
 os/connection.c  | 2 +-
 os/utils.c       | 9 ++++++++-
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/dix/globals.c b/dix/globals.c
index f36a938..fd2f991 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -128,6 +128,7 @@ int monitorResolution = 0;
 
 const char *display;
 int displayfd = -1;
+int displayoffset = 0;
 Bool explicit_display = FALSE;
 char *ConnectionInfo;
 
diff --git a/include/opaque.h b/include/opaque.h
index 0ba0d64..4a29b66 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -52,6 +52,7 @@ extern _X_EXPORT int defaultScreenSaverBlanking;
 extern _X_EXPORT int defaultScreenSaverAllowExposures;
 extern _X_EXPORT const char *display;
 extern _X_EXPORT int displayfd;
+extern _X_EXPORT int displayoffset;
 extern _X_EXPORT Bool explicit_display;
 
 extern _X_EXPORT int defaultBackingStore;
diff --git a/man/Xserver.man b/man/Xserver.man
index 506e5bb..45f2285 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -127,12 +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
+.B \-displayfd \fIfd[:offset]\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 display number back
-on this file descriptor as a newline-terminated string.  The \-pn option is
-ignored when using \-displayfd.
+on this file descriptor as a newline-terminated string. If the optional parameter
+\fIoffset\fP is set the search for a free display number is started at offset instead of
+the default 0. 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
diff --git a/os/connection.c b/os/connection.c
index 4c1ba4b..30bea75 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -419,7 +419,7 @@ CreateWellKnownSockets(void)
     }
     else { /* -displayfd and no explicit display number */
         Bool found = 0;
-        for (i = 0; i < 65536 - X_TCP_PORT; i++) {
+        for (i = displayoffset; i < 65536 - X_TCP_PORT; i++) {
             if (TryCreateSocket(i, &partial) && !partial) {
                 found = 1;
                 break;
diff --git a/os/utils.c b/os/utils.c
index 5871ef8..813b73e 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -549,7 +549,8 @@ UseMsg(void)
     ErrorF("-cc int                default color visual class\n");
     ErrorF("-nocursor              disable the cursor\n");
     ErrorF("-core                  generate core dump on fatal error\n");
-    ErrorF("-displayfd fd          file descriptor to write display number to when ready to connect\n");
+    ErrorF("-displayfd fd[:<offset>] file descriptor to write display " \
+           "number to when ready to connect\n");
     ErrorF("-dpi int               screen resolution in dots per inch\n");
 #ifdef DPMSExtension
     ErrorF("-dpms                  disables VESA DPMS monitor control\n");
@@ -783,7 +784,13 @@ ProcessCommandLine(int argc, char *argv[])
         }
         else if (strcmp(argv[i], "-displayfd") == 0) {
             if (++i < argc) {
+                char *tmp;
                 displayfd = atoi(argv[i]);
+                if ((tmp = strchr(argv[i], ':'))) {
+                    displayoffset = atoi(tmp+1);
+                    if (displayoffset < 0)
+                        displayoffset = 0;
+                }
 #ifdef LOCK_SERVER
                 nolock = TRUE;
 #endif
-- 
2.1.4



More information about the xorg-devel mailing list