[PATCH xorg-gtest 1/8] xserver: don't throw exceptions on failed startup
Peter Hutterer
peter.hutterer at who-t.net
Tue Oct 9 22:14:26 PDT 2012
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 at who-t.net>
---
src/xserver.cpp | 18 +++++++++++-------
1 file 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) {
--
1.7.11.4
More information about the xorg-devel
mailing list