kms: Restore VT settings when crashed
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 31 Jul 2012 10:43:42 +0000 (13:43 +0300)
committerQt by Nokia <qt-info@nokia.com>
Fri, 10 Aug 2012 06:03:31 +0000 (08:03 +0200)
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 <kwangwoong.lee@lge.com>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
src/plugins/platforms/kms/qkmsvthandler.cpp
src/plugins/platforms/kms/qkmsvthandler.h

index 88ca4bf..744ac80 100644 (file)
 ****************************************************************************/
 
 #include <qkmsvthandler.h>
+#include <QtCore/private/qcrashhandler_p.h>
+#include <QtGui/private/qguiapplication_p.h>
 #include <sys/ioctl.h>
 #include <linux/vt.h>
 #include <linux/kd.h>
-#include <QDebug>
 
 #ifdef K_OFF
 #define KBD_OFF_MODE K_OFF
 
 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
index 311ea24..c025428 100644 (file)
@@ -55,6 +55,10 @@ public:
     ~QKmsVTHandler();
 
 private:
+    void cleanup();
+    static void crashHandler();
+
+    static QKmsVTHandler *self;
     int m_tty;
     int m_oldKbdMode;
 };