summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Martin <consume.noise@gmail.com>2012-10-02 01:22:46 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2012-10-04 15:46:55 +1000
commit4dd5353497395fb1fd38d235e9b27b028d564923 (patch)
treea1f6f6777027e46598a6fc237ee1f3516c0d12de /src
parentec9051696dc3c2916849b1676906cf56bcf1c1de (diff)
xserver: use SIGUSR1 to wait for XServer startup
Set the signal handler for SIGUSR1 to SIG_IGN. The XServer will test for this on startup and sends a SIGUSR1 when it's ready for connections. We wait for 1sec to receive this signal from the XServer. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/xserver.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 28f2eca..2ff718d 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -330,6 +330,26 @@ void xorg::testing::XServer::Start(const std::string &program) {
std::vector<std::string> args;
std::map<std::string, std::string>::iterator it;
+ std::string err_msg;
+
+ sigset_t sig_mask;
+ struct timespec sig_timeout = {1, 0}; /* 1 sec + 0 nsec */
+
+ /* add SIGUSR1 to the signal mask */
+ sigemptyset(&sig_mask);
+ sigaddset(&sig_mask, SIGUSR1);
+ if (sigprocmask(SIG_BLOCK, &sig_mask, NULL)) {
+ err_msg.append("Failed to set signal mask: ");
+ err_msg.append(std::strerror(errno));
+ throw std::runtime_error(err_msg);
+ }
+ /* set SIGUSR1 handler to SIG_IGN, XServer tests for this and will
+ * send SIGUSR1 when ready */
+ if (SIG_ERR == signal(SIGUSR1, SIG_IGN)) {
+ err_msg.append("Failed to set signal handler: ");
+ err_msg.append(std::strerror(errno));
+ throw std::runtime_error(err_msg);
+ }
args.push_back(std::string(GetDisplayString()));
@@ -345,6 +365,17 @@ void xorg::testing::XServer::Start(const std::string &program) {
char *sleepwait = getenv("XORG_GTEST_XSERVER_SIGSTOP");
if (sleepwait)
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 {
+ err_msg.append("Error while waiting for XServer startup: ");
+ }
+ err_msg.append(std::strerror(errno));
+ throw std::runtime_error(err_msg);
+ }
}
}