[PATCH xorg-gtest 1/2] Check if a server is already running on the chosen display name

Chase Douglas chase.douglas at canonical.com
Fri May 25 08:22:10 PDT 2012


Otherwise, our server will silently die and we will connect to the
already running server without knowing.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 src/environment.cpp |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/environment.cpp b/src/environment.cpp
index 9e58e4a..68e05ce 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -104,6 +104,16 @@ void xorg::testing::Environment::SetUp() {
   static char display_string[6];
   snprintf(display_string, 6, ":%d", d_->display);
 
+  Display* test_display = XOpenDisplay(display_string);
+  if (test_display) {
+    XCloseDisplay(test_display);
+    std::string message;
+    message += "A server is already running on ";
+    message += display_string;
+    message += ".";
+    throw std::runtime_error(message);
+  }
+
   d_->process.Start(d_->path_to_server, d_->path_to_server.c_str(),
                     display_string,
                     "-logfile", d_->path_to_log_file.c_str(),
@@ -113,7 +123,7 @@ void xorg::testing::Environment::SetUp() {
   Process::SetEnv("DISPLAY", display_string, true);
 
   for (int i = 0; i < 10; ++i) {
-    Display* test_display = XOpenDisplay(NULL);
+    test_display = XOpenDisplay(NULL);
 
     if (test_display) {
       XCloseDisplay(test_display);
-- 
1.7.9.5



More information about the xorg-devel mailing list