kms: Restore VT settings when crashed

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>
bb10
Laszlo Agocs 2012-07-31 13:43:42 +03:00 committed by Qt by Nokia
parent fa08b143f3
commit 8ec3a419d1
2 changed files with 29 additions and 2 deletions

View File

@ -40,10 +40,11 @@
****************************************************************************/
#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
@ -53,20 +54,36 @@
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;
@ -74,4 +91,10 @@ QKmsVTHandler::~QKmsVTHandler()
ioctl(m_tty, KDSKBMODE, m_oldKbdMode);
}
void QKmsVTHandler::crashHandler()
{
Q_ASSERT(self);
self->cleanup();
}
QT_END_NAMESPACE

View File

@ -55,6 +55,10 @@ public:
~QKmsVTHandler();
private:
void cleanup();
static void crashHandler();
static QKmsVTHandler *self;
int m_tty;
int m_oldKbdMode;
};