Improved externremux script termination (#455)

This commit is contained in:
schmirl 2008-10-31 11:41:06 +00:00
parent 84f994384a
commit 30ebb2dad1
3 changed files with 31 additions and 10 deletions

View File

@ -27,6 +27,7 @@ Rolf Ahrenberg
for removing pre VDR 1.4 legacy code for removing pre VDR 1.4 legacy code
for fixing output format of some debug messages for fixing output format of some debug messages
for replacing private members by cThread::Running()/Active() for replacing private members by cThread::Running()/Active()
for improving externremux script termination
Rantanen Teemu Rantanen Teemu
for providing vdr-incompletesections.diff for providing vdr-incompletesections.diff

View File

@ -1,6 +1,7 @@
eDR Plugin 'streamdev' Revision History eDR Plugin 'streamdev' Revision History
--------------------------------------- ---------------------------------------
- improved externremux script termination (thanks to Rolf Ahrenberg)
- use cThread::Running()/Active() instead of private members (thanks to - use cThread::Running()/Active() instead of private members (thanks to
Rolf Ahrenberg) Rolf Ahrenberg)
- fixed output format of some debug messages (thanks to Rolf Ahrenberg) - fixed output format of some debug messages (thanks to Rolf Ahrenberg)

View File

@ -27,7 +27,7 @@ public:
cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter): cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter):
m_ResultBuffer(ResultBuffer), m_ResultBuffer(ResultBuffer),
m_Active(false), m_Active(false),
m_Process(0), m_Process(-1),
m_Inpipe(0), m_Inpipe(0),
m_Outpipe(0) m_Outpipe(0)
{ {
@ -67,8 +67,12 @@ cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter):
close(i); //close all dup'ed filedescriptors close(i); //close all dup'ed filedescriptors
std::string cmd = std::string(opt_remux) + " " + Parameter; std::string cmd = std::string(opt_remux) + " " + Parameter;
execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL); if (execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL) == -1) {
_exit(-1); esyslog("streamdev-server: externremux script '%s' execution failed: %m", cmd.c_str());
_exit(-1);
}
// should never be reached
_exit(0);
} }
close(inpipe[0]); close(inpipe[0]);
@ -83,16 +87,31 @@ cTSExt::~cTSExt()
m_Active = false; m_Active = false;
Cancel(3); Cancel(3);
if (m_Process > 0) { if (m_Process > 0) {
// close pipes
close(m_Outpipe); close(m_Outpipe);
close(m_Inpipe); close(m_Inpipe);
kill(m_Process, SIGTERM); // signal and wait for termination
for (int i = 0; waitpid(m_Process, NULL, WNOHANG) == 0; i++) { if (kill(m_Process, SIGINT) < 0) {
if (i == 20) { esyslog("streamdev-server: externremux SIGINT failed: %m");
esyslog("streamdev-server: externremux process won't stop - killing it");
kill(m_Process, SIGKILL);
}
cCondWait::SleepMs(100);
} }
else {
int i = 0;
int retval;
while ((retval = waitpid(m_Process, NULL, WNOHANG)) == 0) {
if ((++i % 20) == 0) {
esyslog("streamdev-server: externremux process won't stop - killing it");
kill(m_Process, SIGKILL);
}
cCondWait::SleepMs(100);
}
if (retval < 0)
esyslog("streamdev-server: externremux process waitpid failed: %m");
else
Dprintf("streamdev-server: externremux child (%d) exited as expected\n", m_Process);
}
m_Process = -1;
} }
} }