Permalink
Browse files

Fix SIGINT/SIGTERM handling during video playback.

This was broken when SignalHandler was introduced.
There were two problems:
  1/ Calling QCoreApplication::exit()/quit() doesn't actually make the
     program exit if it is in the video playback loop since we take
     over the UI event loop. This has been fixed by periodically
     checking SignalHandler::IsExiting() and setting TV::wantsToExit
     if it is true.
  2/ The VideoOutputXv already had a signal handler for SIGINT, but
     so when we exit playback the first time we were resetting the
     SIGINT handler. This has been fixed by using the
     SignalHandler::SetHandler() method introduced in the last commit
     instead of registering a signal handler ourselves and making the
     new signal handler call QCoreApplication::exit() instead of exit().
  • Loading branch information...
1 parent f3fb6f0 commit f9a46e0683ad9cf7fe04a9c523247dbe48105bae @daniel-kristjansson daniel-kristjansson committed Jul 30, 2012
Showing with 28 additions and 11 deletions.
  1. +6 −0 mythtv/libs/libmythtv/tv_play.cpp
  2. +22 −11 mythtv/libs/libmythtv/util-xv.cpp
@@ -17,6 +17,7 @@ using namespace std;
#include <QFile>
#include <QDir>
+#include "signalhandling.h"
#include "mythdb.h"
#include "tv_play.h"
#include "tv_rec.h"
@@ -1369,6 +1370,11 @@ void TV::PlaybackLoop(void)
while (true)
{
qApp->processEvents();
+ if (SignalHandler::IsExiting())
+ {
+ wantsToQuit = true;
+ return;
+ }
TVState state = GetState(0);
if ((kState_Error == state) || (kState_None == state))
@@ -1,12 +1,13 @@
-// POSIX headers
-#include <signal.h>
-
// C++ headers
#include <iostream>
#include <cstdlib>
using namespace std;
-// MythTH headers
+// Qt headers
+#include <QCoreApplication>
+
+// MythTV headers
+#include "signalhandling.h"
#include "mythlogging.h"
#include "mythxdisplay.h"
#include "util-xv.h"
@@ -22,16 +23,24 @@ QMap<int,port_info> open_xv_ports;
void close_all_xv_ports_signal_handler(int sig)
{
- LOG(VB_GENERAL, LOG_INFO, QString("Signal: %1").arg(sys_siglist[sig]));
+ LOG(VB_GENERAL, LOG_CRIT, QString("Signal: %1").arg(sys_siglist[sig]));
QMap<int,port_info>::iterator it;
for (it = open_xv_ports.begin(); it != open_xv_ports.end(); ++it)
{
restore_port_attributes((*it).port);
- LOG(VB_GENERAL, LOG_INFO, QString("Ungrabbing XVideo port: %1")
+ LOG(VB_GENERAL, LOG_CRIT, QString("Ungrabbing XVideo port: %1")
.arg((*it).port));
XvUngrabPort((*it).disp->GetDisplay(), (*it).port, CurrentTime);
}
- exit(GENERIC_EXIT_NOT_OK);
+ QCoreApplication::exit(GENERIC_EXIT_NOT_OK);
+}
+static void close_all_xv_ports_signal_handler_SIGINT(void)
+{
+ close_all_xv_ports_signal_handler(SIGINT);
+}
+static void close_all_xv_ports_signal_handler_SIGTERM(void)
+{
+ close_all_xv_ports_signal_handler(SIGTERM);
}
void save_port_attributes(int port)
@@ -94,8 +103,10 @@ bool add_open_xv_port(MythXDisplay *disp, int port)
QByteArray ascii_name = "XV_SET_DEFAULTS";
const char *name = ascii_name.constData();
ret = xv_is_attrib_supported(disp, port, name);
- // TODO enable more catches after 0.19 is out -- dtk
- signal(SIGINT, close_all_xv_ports_signal_handler);
+ SignalHandler::SetHandler(
+ SIGINT, close_all_xv_ports_signal_handler_SIGINT);
+ SignalHandler::SetHandler(
+ SIGTERM, close_all_xv_ports_signal_handler_SIGTERM);
}
return ret;
}
@@ -108,8 +119,8 @@ void del_open_xv_port(int port)
if (!open_xv_ports.count())
{
- // TODO enable more catches 0.19 is out -- dtk
- signal(SIGINT, SIG_DFL);
+ SignalHandler::SetHandler(SIGINT, NULL);
+ SignalHandler::SetHandler(SIGTERM, NULL);
}
}
}

0 comments on commit f9a46e0

Please sign in to comment.