diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-10-16 14:33:12 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-10-17 13:14:38 +1000 |
commit | d35d47be00c3b266df6b7bcda2e45ab74b3956f1 (patch) | |
tree | 1243e47491d8f4bc1699557e0b3fb83cf205ed59 /src | |
parent | ef25a6b6f3f387a119ab9261f37479fe415702d4 (diff) |
xserver: add default X IO error handler
Once a server is started, set the X IO error handler to throw an exception.
This way our test cases will survive a server crash and googletest will just
continue with the next test case instead of exiting the process completely.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/xserver.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/xserver.cpp b/src/xserver.cpp index 1ba4e08..1ff8ee8 100644 --- a/src/xserver.cpp +++ b/src/xserver.cpp @@ -45,6 +45,7 @@ #include <fstream> #include <X11/Xlib.h> +#include <X11/Xlibint.h> #include <X11/extensions/XInput2.h> struct xorg::testing::XServer::Private { @@ -295,6 +296,20 @@ const std::string& xorg::testing::XServer::GetVersion(void) { return d_->version; } +static int _x_io_error_handler(Display *dpy) +{ + throw xorg::testing::XIOError("Connection to X Server lost. Possible server crash."); +} + +void xorg::testing::XServer::RegisterXIOErrorHandler() +{ + XIOErrorHandler old_handler; + old_handler = XSetIOErrorHandler(_x_io_error_handler); + + if (old_handler != _XDefaultIOError) + XSetIOErrorHandler(old_handler); +} + void xorg::testing::XServer::Start(const std::string &program) { TestStartup(); @@ -351,6 +366,8 @@ void xorg::testing::XServer::Start(const std::string &program) { sigemptyset(&sig_mask); sigaddset(&sig_mask, SIGCHLD); sigprocmask(SIG_UNBLOCK, &sig_mask, NULL); + + RegisterXIOErrorHandler(); } bool xorg::testing::XServer::Terminate(unsigned int timeout) { |