From 8ec3a419d12294c07ae4ea7970caa21a22f82182 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 31 Jul 2012 13:43:42 +0300 Subject: [PATCH] kms: Restore VT settings when crashed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This does the job of keeping the terminal keyboard working when the application segfaults but is somewhat unsafe because ioctl() is not async-signal safe. Change-Id: Ie6728a4252e18c29bba8f8308e6c00d4a1eb6a8e Reviewed-by: Elvis Lee Reviewed-by: Jørgen Lind --- src/plugins/platforms/kms/qkmsvthandler.cpp | 27 +++++++++++++++++++++++++-- src/plugins/platforms/kms/qkmsvthandler.h | 4 ++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/kms/qkmsvthandler.cpp b/src/plugins/platforms/kms/qkmsvthandler.cpp index 88ca4bf..744ac80 100644 --- a/src/plugins/platforms/kms/qkmsvthandler.cpp +++ b/src/plugins/platforms/kms/qkmsvthandler.cpp @@ -40,10 +40,11 @@ ****************************************************************************/ #include +#include +#include #include #include #include -#include #ifdef K_OFF #define KBD_OFF_MODE K_OFF @@ -53,25 +54,47 @@ QT_BEGIN_NAMESPACE +QKmsVTHandler *QKmsVTHandler::self = 0; + QKmsVTHandler::QKmsVTHandler(QObject *parent) : QObject(parent), m_tty(-1) { + Q_ASSERT(!self); + self = this; + if (!isatty(0)) return; m_tty = 0; ioctl(m_tty, KDGKBMODE, &m_oldKbdMode); - if (!qgetenv("QT_KMS_TTYKBD").toInt()) + if (!qgetenv("QT_KMS_TTYKBD").toInt()) { ioctl(m_tty, KDSKBMODE, KBD_OFF_MODE); + QGuiApplicationPrivate *appd = QGuiApplicationPrivate::instance(); + Q_ASSERT(appd); + QSegfaultHandler::initialize(appd->argv, appd->argc); + QSegfaultHandler::installCrashHandler(crashHandler); + } } QKmsVTHandler::~QKmsVTHandler() { + self->cleanup(); + self = 0; +} + +void QKmsVTHandler::cleanup() +{ if (m_tty == -1) return; ioctl(m_tty, KDSKBMODE, m_oldKbdMode); } +void QKmsVTHandler::crashHandler() +{ + Q_ASSERT(self); + self->cleanup(); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/kms/qkmsvthandler.h b/src/plugins/platforms/kms/qkmsvthandler.h index 311ea24..c025428 100644 --- a/src/plugins/platforms/kms/qkmsvthandler.h +++ b/src/plugins/platforms/kms/qkmsvthandler.h @@ -55,6 +55,10 @@ public: ~QKmsVTHandler(); private: + void cleanup(); + static void crashHandler(); + + static QKmsVTHandler *self; int m_tty; int m_oldKbdMode; }; -- 2.7.4