diff options
author | Chase Douglas <chase.douglas@canonical.com> | 2012-05-25 07:40:49 -0700 |
---|---|---|
committer | Chase Douglas <chase.douglas@canonical.com> | 2012-06-04 09:57:59 -0700 |
commit | 68b4ef7b5f100a14a5aee33d5c34ef8b29bafa3b (patch) | |
tree | 84dcec2c6f1b473139fd719ea8a1fac319f2324d | |
parent | 2b5f29b84b87040be9ad6ce8d986b23bab253189 (diff) |
Check if a server is already running on the chosen display name
Otherwise, our server will silently die and we will connect to the
already running server without knowing.
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/environment.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
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); |