Skip to content
Browse files

Moved UNIX signal handling to signalhandling.cpp

According to Qt docs, we were doing something very bad.  We were using Qt
functions inside our signal handler.  This is expressly forbidden.  I reworked
the handlers to their scheme for safety.

See: http://qt-project.org/doc/qt-4.8/unix-signals.html
  • Loading branch information...
1 parent c2132cf commit baee9ac9e7750f19a0b50d8d80dd80a863f48f55 @Beirdo Beirdo committed
View
6 mythtv/libs/libmythbase/libmythbase.pro
@@ -24,7 +24,7 @@ HEADERS += mythmiscutil.h mythhdd.h mythcdrom.h autodeletedeque.h dbutil.h
HEADERS += mythhttppool.h mythhttphandler.h mythdeque.h mythlogging.h
HEADERS += mythbaseutil.h referencecounter.h version.h mythcommandlineparser.h
HEADERS += mythscheduler.h filesysteminfo.h hardwareprofile.h serverpool.h
-HEADERS += plist.h
+HEADERS += plist.h signalhandling.h
SOURCES += mthread.cpp mthreadpool.cpp
SOURCES += mythsocket.cpp mythsocketthread.cpp msocketdevice.cpp
@@ -39,7 +39,7 @@ SOURCES += mythhdd.cpp mythcdrom.cpp dbutil.cpp
SOURCES += mythhttppool.cpp mythhttphandler.cpp logging.cpp loggingserver.cpp
SOURCES += referencecounter.cpp mythcommandlineparser.cpp
SOURCES += filesysteminfo.cpp hardwareprofile.cpp serverpool.cpp
-SOURCES += plist.cpp
+SOURCES += plist.cpp signalhandling.cpp
win32:SOURCES += msocketdevice_win.cpp
unix {
@@ -66,7 +66,7 @@ inc.files += mythtranslation.h iso639.h iso3166.h mythmedia.h mythmiscutil.h
inc.files += mythcdrom.h autodeletedeque.h dbutil.h mythhttppool.h mythdeque.h
inc.files += referencecounter.h mythcommandlineparser.h mthread.h mthreadpool.h
inc.files += filesysteminfo.h hardwareprofile.h bonjourregister.h serverpool.h
-inc.files += plist.h
+inc.files += plist.h signalhandling.h
# Allow both #include <blah.h> and #include <libmythbase/blah.h>
inc2.path = $${PREFIX}/include/mythtv/libmythbase
View
113 mythtv/libs/libmythbase/loggingserver.cpp
@@ -11,6 +11,7 @@
#include <QMap>
#include <QRegExp>
#include <QTimer>
+#include <QSocketNotifier>
#include <iostream>
using namespace std;
@@ -88,7 +89,8 @@ static QWaitCondition logMsgListNotEmpty;
#define MAX_STRING_LENGTH (LOGLINE_MAX+120)
#ifndef _WIN32
-void logSighup( int signum, siginfo_t *info, void *secret );
+static int sighupFd[2];
+void logSighup(int signum);
#endif
@@ -600,10 +602,25 @@ void DBLoggerThread::stop(void)
+#ifndef _WIN32
+/// \brief UNIX-side SIGHUP signal handler. Hand it off to the Qt-size via
+/// a socketpair so Qt code can safely be used.
+
+void logSighup(int signum)
+{
+ (void)signum;
+ char a = 1;
+ int ret = ::write(sighupFd[0], &a, sizeof(a));
+ (void)ret;
+}
+#endif
+
/// \brief LogServerThread constructor.
LogServerThread::LogServerThread() :
- MThread("LogServer"), m_aborted(false)
+ MThread("LogServer"), m_aborted(false), m_zmqContext(NULL),
+ m_zmqInSock(NULL), m_zmqPubSock(NULL), m_heartbeatTimer(NULL),
+ m_shutdownTimer(NULL), m_sighupNotifier(NULL)
{
moveToThread(qthread());
}
@@ -625,6 +642,26 @@ void LogServerThread::run(void)
logThreadFinished = false;
QMutexLocker locker(&logThreadStartedMutex);
+#ifndef _WIN32
+ if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sighupFd))
+ {
+ LOG(VB_GENERAL, LOG_ERR, "Couldn't create HUP socketpair");
+ qApp->quit();
+ }
+ m_sighupNotifier = new QSocketNotifier(sighupFd[1], QSocketNotifier::Read,
+ this);
+ connect(m_sighupNotifier, SIGNAL(activated(int)),
+ this, SLOT(handleSigHup()));
+
+ /* Setup SIGHUP */
+ LOG(VB_GENERAL, LOG_NOTICE, "Setting up SIGHUP handler");
+ struct sigaction sa;
+ sa.sa_handler = logSighup;
+ sigemptyset( &sa.sa_mask );
+ sa.sa_flags = SA_RESTART;
+ sigaction( SIGHUP, &sa, NULL );
+#endif
+
qRegisterMetaType<QList<QByteArray> >("QList<QByteArray>");
m_zmqContext = nzmqt::createDefaultContext(NULL);
@@ -678,6 +715,19 @@ void LogServerThread::run(void)
logThreadFinished = true;
+ delete m_sighupNotifier;
+
+#ifndef _WIN32
+ ::close(sighupFd[0]);
+ ::close(sighupFd[1]);
+
+ /* Tear down SIGHUP */
+ sa.sa_handler = SIG_DFL;
+ sigemptyset( &sa.sa_mask );
+ sa.sa_flags = SA_RESTART;
+ sigaction( SIGHUP, &sa, NULL );
+#endif
+
m_heartbeatTimer->stop();
delete m_heartbeatTimer;
@@ -722,6 +772,30 @@ void LogServerThread::pingClient(QString clientId)
m_zmqInSock->sendMessage(msg);
}
+/// \brief SIGHUP handler - reopen all open logfiles for logrollers
+void LogServerThread::handleSigHup(void)
+{
+#ifndef _WIN32
+ m_sighupNotifier->setEnabled(false);
+
+ char tmp;
+ int ret = ::read(sighupFd[1], &tmp, sizeof(tmp));
+ (void)ret;
+
+ LOG(VB_GENERAL, LOG_INFO, "SIGHUP received, rolling log files.");
+
+ /* SIGHUP was sent. Close and reopen debug logfiles */
+ QMutexLocker locker(&loggerMapMutex);
+ QMap<QString, LoggerBase *>::iterator it;
+ for (it = loggerMap.begin(); it != loggerMap.end(); ++it)
+ {
+ it.value()->reopen();
+ }
+
+ m_sighupNotifier->setEnabled(true);
+#endif
+}
+
/// \brief Fires off when no clients are left (other than the current daemon)
/// for 5 minutes.
@@ -1017,22 +1091,6 @@ static QTime memory_time;
#endif
-#ifndef _WIN32
-/// \brief SIGHUP handler - reopen all open logfiles for logrollers
-void logSighup( int signum, siginfo_t *info, void *secret )
-{
- LOG(VB_GENERAL, LOG_INFO, "SIGHUP received, rolling log files.");
-
- /* SIGHUP was sent. Close and reopen debug logfiles */
- QMutexLocker locker(&loggerMapMutex);
- QMap<QString, LoggerBase *>::iterator it;
- for (it = loggerMap.begin(); it != loggerMap.end(); ++it)
- {
- it.value()->reopen();
- }
-}
-#endif
-
/// \brief Entry point to start logging for the application. This will
/// start up all of the threads needed.
@@ -1054,16 +1112,6 @@ void logServerStart(void)
if (!logServerThread)
logServerThread = new LogServerThread();
-#ifndef _WIN32
- /* Setup SIGHUP */
- LOG(VB_GENERAL, LOG_NOTICE, "Setting up SIGHUP handler");
- struct sigaction sa;
- sa.sa_sigaction = logSighup;
- sigemptyset( &sa.sa_mask );
- sa.sa_flags = SA_RESTART | SA_SIGINFO;
- sigaction( SIGHUP, &sa, NULL );
-#endif
-
QMutexLocker locker(&logThreadStartedMutex);
logServerThread->start();
logThreadStarted.wait(locker.mutex());
@@ -1079,15 +1127,6 @@ void logServerStop(void)
logServerThread->wait();
}
-#ifndef _WIN32
- /* Tear down SIGHUP */
- struct sigaction sa;
- sa.sa_handler = SIG_DFL;
- sigemptyset( &sa.sa_mask );
- sa.sa_flags = SA_RESTART;
- sigaction( SIGHUP, &sa, NULL );
-#endif
-
QMutexLocker locker(&loggerMapMutex);
QMap<QString, LoggerBase *>::iterator it;
for (it = loggerMap.begin(); it != loggerMap.end(); ++it)
View
6 mythtv/libs/libmythbase/loggingserver.h
@@ -2,6 +2,7 @@
#define LOGGINGSERVER_H_
#include <QMutexLocker>
+#include <QSocketNotifier>
#include <QMutex>
#include <QQueue>
#include <QTime>
@@ -128,6 +129,8 @@ typedef QList<LogMessage *> LogMessageList;
class LogServerThread : public QObject, public MThread
{
Q_OBJECT;
+
+ friend void logSighup(int signum);
public:
LogServerThread();
~LogServerThread();
@@ -143,6 +146,8 @@ class LogServerThread : public QObject, public MThread
QTimer *m_heartbeatTimer; ///< 1s repeating timer for client
/// heartbeats
QTimer *m_shutdownTimer; ///< 5 min timer to shut down if no clients
+ QSocketNotifier *m_sighupNotifier; ///< Notifier to synchronize to UNIX
+ /// signal SIGHUP safely
void forwardMessage(LogMessage *msg);
void pingClient(QString clientId);
@@ -150,6 +155,7 @@ class LogServerThread : public QObject, public MThread
void receivedMessage(const QList<QByteArray>&);
void checkHeartBeats(void);
void shutdownTimerExpired(void);
+ void handleSigHup(void);
};
class QWaitCondition;
View
169 mythtv/libs/libmythbase/signalhandling.cpp
@@ -0,0 +1,169 @@
+#include <QObject>
+#include <QSocketNotifier>
+#include <QCoreApplication>
+#include <QList>
+
+#include <stdint.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <iostream>
+
+using namespace std;
+
+#include "mythlogging.h"
+#include "exitcodes.h"
+#include "signalhandling.h"
+
+int SignalHandler::sigFd[2];
+
+SignalHandler::SignalHandler(QList<int> &signallist, QObject *parent) :
+ QObject(parent), m_notifier(NULL), m_usr1Handler(NULL), m_usr2Handler(NULL)
+{
+#ifndef _WIN32
+ if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigFd))
+ {
+ cerr << "Couldn't create socketpair" << endl;
+ return;
+ }
+ m_notifier = new QSocketNotifier(sigFd[1], QSocketNotifier::Read, this);
+ connect(m_notifier, SIGNAL(activated(int)), this, SLOT(handleSignal()));
+
+ struct sigaction sa;
+ sa.sa_handler = SignalHandler::signalHandler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART;
+
+ QList<int>::iterator it = signallist.begin();
+ for( ; it != signallist.end(); ++it )
+ {
+ switch (*it)
+ {
+ case SIGINT:
+ sigaction(*it, &sa, NULL);
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGINT handler");
+ break;
+ case SIGTERM:
+ sigaction(*it, &sa, NULL);
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGTERM handler");
+ break;
+ case SIGSEGV:
+ sigaction(*it, &sa, NULL);
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGSEGV handler");
+ break;
+ case SIGABRT:
+ sigaction(*it, &sa, NULL);
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGABRT handler");
+ break;
+ default:
+ cerr << "No handler for signal " << *it << endl;
+ break;
+ }
+ }
+#endif
+}
+
+SignalHandler::~SignalHandler()
+{
+#ifndef _WIN32
+ if (m_notifier)
+ {
+ ::close(sigFd[0]);
+ ::close(sigFd[1]);
+ delete m_notifier;
+ }
+
+ signal(SIGINT, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ signal(SIGSEGV, SIG_DFL);
+ signal(SIGABRT, SIG_DFL);
+
+ if (m_usr1Handler)
+ {
+ signal(SIGUSR1, SIG_DFL);
+ m_usr1Handler = NULL;
+ }
+
+ if (m_usr2Handler)
+ {
+ signal(SIGUSR2, SIG_DFL);
+ m_usr2Handler = NULL;
+ }
+#endif
+}
+
+void SignalHandler::AddHandler(int signum, void (*handler)(void))
+{
+ switch (signum)
+ {
+ case SIGUSR1:
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGUSR1 handler");
+ m_usr1Handler = handler;
+ break;
+ case SIGUSR2:
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGUSR2 handler");
+ m_usr2Handler = handler;
+ break;
+ default:
+ LOG(VB_GENERAL, LOG_CRIT, QString("Unhandled signal %1").arg(signum));
+ break;
+ }
+}
+
+void SignalHandler::signalHandler(int signum)
+{
+ char a = (char)signum;
+ int ret = ::write(sigFd[0], &a, sizeof(a));
+ (void)ret;
+}
+
+void SignalHandler::handleSignal(void)
+{
+ m_notifier->setEnabled(false);
+
+ char a;
+ int ret = ::read(sigFd[1], &a, sizeof(a));
+ int signum = (int)a;
+
+ switch (signum)
+ {
+ case SIGINT:
+ LOG(VB_GENERAL, LOG_CRIT, "Received SIGINT");
+ signal(SIGINT, SIG_DFL);
+ qApp->quit();
+ break;
+ case SIGTERM:
+ LOG(VB_GENERAL, LOG_CRIT, "Received SIGTERM");
+ signal(SIGTERM, SIG_DFL);
+ qApp->quit();
+ break;
+ case SIGSEGV:
+ LOG(VB_GENERAL, LOG_CRIT, "Received SIGSEGV");
+ qApp->quit();
+ break;
+ case SIGABRT:
+ LOG(VB_GENERAL, LOG_CRIT, "Received SIGABRT");
+ qApp->quit();
+ break;
+ case SIGUSR1:
+ LOG(VB_GENERAL, LOG_CRIT, "Received SIGUSR1");
+ if (m_usr1Handler)
+ m_usr1Handler();
+ break;
+ case SIGUSR2:
+ LOG(VB_GENERAL, LOG_CRIT, "Received SIGUSR2");
+ if (m_usr2Handler)
+ m_usr2Handler();
+ break;
+ default:
+ LOG(VB_GENERAL, LOG_CRIT, QString("Recieved unexpected signal %1")
+ .arg(signum));
+ break;
+ }
+ m_notifier->setEnabled(true);
+}
+
+/*
+ * vim:ts=4:sw=4:ai:et:si:sts=4
+ */
View
45 mythtv/libs/libmythbase/signalhandling.h
@@ -0,0 +1,45 @@
+#ifndef SIGNALHANDLING_H_
+#define SIGNALHANDLING_H_
+
+#include <QObject>
+#include <QSocketNotifier>
+#include <QList>
+
+#include <stdint.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include "mythbaseexp.h" // MBASE_PUBLIC , etc.
+#include "mthread.h"
+
+/// \brief A container object to handle UNIX signals in the Qt space correctly
+class MBASE_PUBLIC SignalHandler: public QObject
+{
+ Q_OBJECT
+
+ public:
+ SignalHandler(QList<int> &signallist, QObject *parent = NULL);
+ ~SignalHandler();
+
+ void AddHandler(int signal, void (*handler)(void));
+
+ // Unix signal handler.
+ static void signalHandler(int signum);
+
+ public slots:
+ // Qt signal handler.
+ void handleSignal(void);
+
+ private:
+ static int sigFd[2];
+ QSocketNotifier *m_notifier;
+
+ void (*m_usr1Handler)(void);
+ void (*m_usr2Handler)(void);
+};
+
+#endif
+
+/*
+ * vim:ts=4:sw=4:ai:et:si:sts=4
+ */
View
1 mythtv/programs/mythavtest/main.cpp
@@ -22,6 +22,7 @@ using namespace std;
#include "compat.h"
#include "dbcheck.h"
#include "mythlogging.h"
+#include "signalhandling.h"
// libmythui
#include "mythuihelper.h"
View
16 mythtv/programs/mythbackend/main.cpp
@@ -10,6 +10,7 @@
#include <QDir>
#include <QMap>
+#include "signalhandling.h"
#include "commandlineparser.h"
#include "scheduledrecording.h"
#include "previewgenerator.h"
@@ -46,13 +47,6 @@
#define UNUSED_FILENO 3
#endif
-static void qt_exit(int)
-{
- signal(SIGINT, SIG_DFL);
- signal(SIGTERM, SIG_DFL);
- QCoreApplication::exit(GENERIC_EXIT_OK);
-}
-
int main(int argc, char **argv)
{
MythBackendCommandLineParser cmdline;
@@ -100,8 +94,12 @@ int main(int argc, char **argv)
close(0);
CleanupGuard callCleanup(cleanup);
- signal(SIGINT, qt_exit);
- signal(SIGTERM, qt_exit);
+
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
View
5 mythtv/programs/mythbackend/main_helpers.cpp
@@ -216,11 +216,6 @@ bool setupTVs(bool ismaster, bool &error)
void cleanup(void)
{
- signal(SIGTERM, SIG_DFL);
-#ifndef _MSC_VER
- signal(SIGUSR1, SIG_DFL);
-#endif
-
if (mainServer)
mainServer->Stop();
View
7 mythtv/programs/mythccextractor/main.cpp
@@ -18,6 +18,7 @@ using namespace std;
#include "programinfo.h"
#include "ringbuffer.h"
#include "exitcodes.h"
+#include "signalhandling.h"
namespace {
void cleanup()
@@ -140,6 +141,12 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(
false/*use gui*/, false/*prompt for backend*/,
View
8 mythtv/programs/mythcommflag/main.cpp
@@ -38,6 +38,7 @@ using namespace std;
#include "commandlineparser.h"
#include "mythtranslation.h"
#include "mythlogging.h"
+#include "signalhandling.h"
// Commercial Flagging headers
#include "CommDetectorBase.h"
@@ -1125,6 +1126,13 @@ int main(int argc, char *argv[])
return retval;
CleanupGuard callCleanup(cleanup);
+
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init( false, /*use gui*/
false, /*prompt for backend*/
View
7 mythtv/programs/mythfilldatabase/main.cpp
@@ -27,6 +27,7 @@ using namespace std;
#include "dbcheck.h"
#include "mythsystemevent.h"
#include "mythlogging.h"
+#include "signalhandling.h"
// filldata headers
#include "filldata.h"
@@ -343,6 +344,12 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
View
53 mythtv/programs/mythfrontend/main.cpp
@@ -42,6 +42,7 @@ using namespace std;
#include "scheduledrecording.h"
#include "mythsystemevent.h"
#include "hardwareprofile.h"
+#include "signalhandling.h"
#include "compat.h" // For SIG* on MinGW
#include "exitcodes.h"
@@ -104,6 +105,9 @@ static MythPluginManager *pmanager = NULL;
static void handleExit(bool prompt);
static void resetAllKeys(void);
+void handleSIGUSR1(void);
+void handleSIGUSR2(void);
+
namespace
{
@@ -258,10 +262,6 @@ namespace
gContext = NULL;
delete qApp;
-
-#ifndef _MSC_VER
- signal(SIGUSR1, SIG_DFL);
-#endif
}
class CleanupGuard
@@ -1440,22 +1440,6 @@ static void resetAllKeys(void)
ReloadKeys();
}
-
-static void signal_USR1_handler(int){
- LOG(VB_GENERAL, LOG_NOTICE, "SIGUSR1 received, reloading theme");
- gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
- gCoreContext->ActivateSettingsCache(false);
- GetMythMainWindow()->JumpTo("Reload Theme");
- gCoreContext->ActivateSettingsCache(true);
-}
-
-static void signal_USR2_handler(int)
-{
- LOG(VB_GENERAL, LOG_NOTICE, "SIGUSR2 received, restart LIRC handler");
- GetMythMainWindow()->StartLIRC();
-}
-
-
static int internal_media_init()
{
REG_MEDIAPLAYER("Internal", QT_TRANSLATE_NOOP("MythControls",
@@ -1503,6 +1487,14 @@ int main(int argc, char **argv)
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+ handler.AddHandler(SIGUSR1, handleSIGUSR1);
+ handler.AddHandler(SIGUSR2, handleSIGUSR2);
+#endif
+
#ifdef Q_WS_MACX
// Without this, we can't set focus to any of the CheckBoxSetting, and most
// of the MythPushButton widgets, and they don't use the themed background.
@@ -1705,12 +1697,6 @@ int main(int argc, char **argv)
return GENERIC_EXIT_NO_THEME;
}
-#ifndef _MSC_VER
- // Setup handler for USR1 signals to reload theme
- signal(SIGUSR1, &signal_USR1_handler);
- // Setup handler for USR2 signals to restart LIRC
- signal(SIGUSR2, &signal_USR2_handler);
-#endif
ThemeUpdateChecker *themeUpdateChecker = NULL;
if (gCoreContext->GetNumSetting("ThemeUpdateNofications", 1))
themeUpdateChecker = new ThemeUpdateChecker();
@@ -1779,5 +1765,20 @@ int main(int argc, char **argv)
}
+void handleSIGUSR1(void)
+{
+ LOG(VB_GENERAL, LOG_INFO, "Reloading theme");
+ gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
+ gCoreContext->ActivateSettingsCache(false);
+ GetMythMainWindow()->JumpTo("Reload Theme");
+ gCoreContext->ActivateSettingsCache(true);
+}
+
+void handleSIGUSR2(void)
+{
+ LOG(VB_GENERAL, LOG_INFO, "Restarting LIRC handler");
+ GetMythMainWindow()->StartLIRC();
+}
+
#include "main.moc"
/* vim: set expandtab tabstop=4 shiftwidth=4: */
View
7 mythtv/programs/mythjobqueue/main.cpp
@@ -28,6 +28,7 @@
#include "compat.h"
#include "mythsystemevent.h"
#include "mythlogging.h"
+#include "signalhandling.h"
#define LOC QString("MythJobQueue: ")
#define LOC_WARN QString("MythJobQueue, Warning: ")
@@ -107,6 +108,12 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
View
7 mythtv/programs/mythlcdserver/main.cpp
@@ -23,6 +23,7 @@ using namespace std;
#include "compat.h"
#include "mythtranslation.h"
#include "commandlineparser.h"
+#include "signalhandling.h"
#include "lcdserver.h"
@@ -96,6 +97,12 @@ int main(int argc, char **argv)
}
}
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
// Get the MythTV context and db hooks
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
View
16 mythtv/programs/mythlogserver/main.cpp
@@ -21,6 +21,7 @@ using namespace std;
#include "ringbuffer.h"
#include "exitcodes.h"
#include "loggingserver.h"
+#include "signalhandling.h"
namespace {
void cleanup()
@@ -50,13 +51,6 @@ namespace {
};
}
-static void qt_exit(int)
-{
- signal(SIGINT, SIG_DFL);
- signal(SIGTERM, SIG_DFL);
- qApp->exit(GENERIC_EXIT_OK);
-}
-
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
@@ -99,8 +93,12 @@ int main(int argc, char *argv[])
close(0);
CleanupGuard callCleanup(cleanup);
- signal(SIGINT, qt_exit);
- signal(SIGTERM, qt_exit);
+
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
View
7 mythtv/programs/mythmediaserver/main.cpp
@@ -22,6 +22,7 @@
#include "mythversion.h"
#include "mythsystemevent.h"
#include "commandlineparser.h"
+#include "signalhandling.h"
#include "controlrequesthandler.h"
#include "requesthandler/basehandler.h"
@@ -105,6 +106,12 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
View
7 mythtv/programs/mythmetadatalookup/main.cpp
@@ -20,6 +20,7 @@ using namespace std;
#include "mythconfig.h"
#include "mythcommandlineparser.h"
#include "mythlogging.h"
+#include "signalhandling.h"
#include "lookup.h"
@@ -137,6 +138,12 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
View
7 mythtv/programs/mythpreviewgen/main.cpp
@@ -46,6 +46,7 @@ using namespace std;
#include "commandlineparser.h"
#include "mythsystemevent.h"
#include "mythlogging.h"
+#include "signalhandling.h"
#define LOC QString("MythPreviewGen: ")
#define LOC_WARN QString("MythPreviewGen, Warning: ")
@@ -201,6 +202,12 @@ int main(int argc, char **argv)
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
LOG(VB_GENERAL, LOG_WARNING, LOC + "Unable to ignore SIGPIPE");
View
7 mythtv/programs/mythshutdown/main.cpp
@@ -20,6 +20,7 @@ using namespace std;
#include "mythlogging.h"
#include "commandlineparser.h"
#include "programinfo.h"
+#include "signalhandling.h"
static void setGlobalSetting(const QString &key, const QString &value)
{
@@ -777,6 +778,12 @@ int main(int argc, char **argv)
if ((retval = cmdline.ConfigureLogging(mask)) != GENERIC_EXIT_OK)
return retval;
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
View
8 mythtv/programs/mythtranscode/main.cpp
@@ -26,6 +26,7 @@ using namespace std;
#include "mythlogging.h"
#include "commandlineparser.h"
#include "recordinginfo.h"
+#include "signalhandling.h"
static void CompleteJob(int jobID, ProgramInfo *pginfo, bool useCutlist,
frm_dir_map_t *deleteMap, int &resultCode);
@@ -371,6 +372,13 @@ int main(int argc, char *argv[])
passthru = true;
CleanupGuard callCleanup(cleanup);
+
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
// Load the context
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
View
7 mythtv/programs/mythtv-setup/main.cpp
@@ -39,6 +39,7 @@
#include "expertsettingseditor.h"
#include "commandlineparser.h"
#include "profilegroup.h"
+#include "signalhandling.h"
using namespace std;
@@ -265,6 +266,12 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
#ifdef Q_WS_MACX
// Without this, we can't set focus to any of the CheckBoxSetting, and most
// of the MythPushButton widgets, and they don't use the themed background.
View
7 mythtv/programs/mythutil/main.cpp
@@ -20,6 +20,7 @@
#include "jobutils.h"
#include "markuputils.h"
#include "messageutils.h"
+#include "signalhandling.h"
int main(int argc, char *argv[])
@@ -75,6 +76,12 @@ int main(int argc, char *argv[])
if (!cmdline.toBool("loglevel"))
logLevel = defaultLevel;
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
{
View
7 mythtv/programs/mythwelcome/main.cpp
@@ -20,6 +20,7 @@
#include "commandlineparser.h"
#include "tv.h"
#include "mythlogging.h"
+#include "signalhandling.h"
// libmythui
#include "mythmainwindow.h"
@@ -73,6 +74,12 @@ int main(int argc, char **argv)
if (cmdline.toBool("setup"))
bShowSettings = true;
+#ifndef _WIN32
+ QList<int> signallist;
+ signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT;
+ SignalHandler handler(signallist);
+#endif
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init())
{

0 comments on commit baee9ac

Please sign in to comment.
Something went wrong with that request. Please try again.