summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-10-09 17:22:31 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-10-10 09:04:22 +1000
commit18e69a49dedc0e6f0627291f04fcdeb8b187c4af (patch)
tree93ee7255db64f5addb364c40e3271bc86b7eae3d
parentf6849f693afd68f1041f58da15fced61fbe14c73 (diff)
xserver: don't throw exceptions on failed startup
Startup failure can be a valid test-case, avoid throwing exceptions around. Instead, update the process state on SIGCHLD, otherwise continue quietly after the timeout. A test that needs the server to be running, will figure out that it isn't once XOpenDisplay() fails. If the signal handling fails, still throw an exception, that's an actual error case. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@ubuntu.com>
-rw-r--r--src/xserver.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 082818c..1ba4e08 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -308,6 +308,7 @@ void xorg::testing::XServer::Start(const std::string &program) {
/* add SIGUSR1 to the signal mask */
sigemptyset(&sig_mask);
sigaddset(&sig_mask, SIGUSR1);
+ sigaddset(&sig_mask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sig_mask, NULL)) {
err_msg.append("Failed to set signal mask: ");
err_msg.append(std::strerror(errno));
@@ -337,16 +338,19 @@ void xorg::testing::XServer::Start(const std::string &program) {
raise(SIGSTOP);
/* wait for SIGUSR1 from XServer */
- if (SIGUSR1 != sigtimedwait(&sig_mask, NULL, &sig_timeout)) {
- if (errno == EAGAIN) {
- err_msg.append("XServer startup timed out: ");
- } else {
+ int recv_sig = sigtimedwait(&sig_mask, NULL, &sig_timeout);
+ if (recv_sig == SIGCHLD) {
+ GetState();
+ } else if (recv_sig != SIGUSR1 && errno != EAGAIN) {
err_msg.append("Error while waiting for XServer startup: ");
- }
- err_msg.append(std::strerror(errno));
- throw std::runtime_error(err_msg);
+ err_msg.append(std::strerror(errno));
+ throw std::runtime_error(err_msg);
}
}
+
+ sigemptyset(&sig_mask);
+ sigaddset(&sig_mask, SIGCHLD);
+ sigprocmask(SIG_UNBLOCK, &sig_mask, NULL);
}
bool xorg::testing::XServer::Terminate(unsigned int timeout) {