Skip to content
Permalink
Browse files

ExternalStreamHandler: Kill miss-behaving external recorders.

  • Loading branch information...
jpoet committed Feb 23, 2018
1 parent 23d74c7 commit 002c7606372f1657fb4857ad708c055d28275cb7
@@ -237,11 +237,6 @@ bool ExternIO::Run(void)
return true;
}

void ExternIO::Term(bool /*force*/)
{
LOG(VB_RECORD, LOG_INFO, QString("ExternIO::Term()"));
}

/* Return true if the process is not, or is no longer running */
bool ExternIO::KillIfRunning(const QString & cmd)
{
@@ -307,6 +302,7 @@ void ExternIO::Fork(void)
}

QString full_command = QString("%1").arg(m_args.join(" "));

if (!KillIfRunning(full_command))
{
// Give it one more chance.
@@ -733,7 +729,8 @@ void ExternalStreamHandler::run(void)
break;
}
}
LOG(VB_RECORD, LOG_INFO, LOC + "run(): " + "shutdown");
LOG(VB_RECORD, LOG_INFO, LOC + "run(): " +
QString("%1 shutdown").arg(_error ? "Error" : "Normal"));

RemoveAllPIDFilters();
SetRunning(false, true, false);
@@ -869,9 +866,21 @@ void ExternalStreamHandler::CloseApp(void)
{
LOG(VB_RECORD, LOG_INFO, LOC +
"CloseRecorder failed, sending kill.");
m_IO->Term();
sleep(5);
m_IO->Term(true);

QString full_command = QString("%1").arg(m_args.join(" "));

if (!m_IO->KillIfRunning(full_command))
{
// Give it one more chance.
usleep(50000);
if (!m_IO->KillIfRunning(full_command))
{
LOG(VB_GENERAL, LOG_ERR,
QString("Unable to kill existing '%1'.")
.arg(full_command));
return;
}
}
}
delete m_IO;
m_IO = 0;
@@ -1014,7 +1023,7 @@ bool ExternalStreamHandler::StopStreaming(void)
.arg(result));
if (!result.startsWith("Warn"))
{
LOG(VB_RECORD, LOG_WARNING, LOC +
LOG(VB_RECORD, LOG_ERR, LOC +
QString("StopStreaming failed: '%1'").arg(result));
_error = true;
}
@@ -1058,7 +1067,7 @@ bool ExternalStreamHandler::ProcessCommand(const QString & cmd, uint timeout,

if (m_IO->Error())
{
LOG(VB_GENERAL, LOG_ERR, "External Recorder in bad state: " +
LOG(VB_GENERAL, LOG_ERR, LOC + "External Recorder in bad state: " +
m_IO->ErrorString());
return false;
}
@@ -1075,7 +1084,7 @@ bool ExternalStreamHandler::ProcessCommand(const QString & cmd, uint timeout,
result = m_IO->GetStatus(timeout);
if (m_IO->Error())
{
LOG(VB_GENERAL, LOG_ERR,
LOG(VB_GENERAL, LOG_ERR, LOC +
"Failed to read from External Recorder: " +
m_IO->ErrorString());
_error = true;
@@ -1114,7 +1123,10 @@ bool ExternalStreamHandler::ProcessCommand(const QString & cmd, uint timeout,
}

if (++m_io_errcnt > 10)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Too many I/O errors.");
_error = true;
}
usleep(timeout);
}

@@ -30,13 +30,13 @@ class ExternIO
QString GetStatus(int timeout = 2500);
int Write(const QByteArray & buffer);
bool Run(void);
void Term(bool force = false);
bool Error(void) const { return !m_error.isEmpty(); }
QString ErrorString(void) const { return m_error; }
void ClearError(void) { m_error.clear(); }

private:
bool KillIfRunning(const QString & cmd);

private:
void Fork(void);

QFileInfo m_app;

0 comments on commit 002c760

Please sign in to comment.
You can’t perform that action at this time.