From 158d4dd5155aeaf0aa9e5f12b22df8639631a3fa Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sat, 3 Dec 2016 15:12:11 +0100 Subject: [PATCH] fix(controller): Handle connection error --- src/components/controller.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 09a86968..14ba6e62 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -276,17 +276,22 @@ void controller::wait_for_xevent() { shared_ptr evt; while (m_running) { try { - int error = 0; - - if ((error = m_connection.connection_has_error()) != 0) { - m_log.err("Error in X event loop, terminating... (%s)", m_connection.error_str(error)); - kill(getpid(), SIGTERM); - } else if ((evt = m_connection.wait_for_event()) != nullptr && m_running) { + if ((evt = m_connection.wait_for_event()) != nullptr && m_running) { m_connection.dispatch_event(evt); } + } catch (xpp::connection_error& err) { + m_log.err("X connection error, terminating... (what: %s)", m_connection.error_str(err.code())); } catch (const exception& err) { m_log.err("Error in X event loop: %s", err.what()); } + + if (m_connection.connection_has_error()) { + break; + } + } + + if (m_running) { + kill(getpid(), SIGTERM); } }