diff options
author | schmirl <schmirl> | 2008-10-31 11:41:12 +0000 |
---|---|---|
committer | schmirl <schmirl> | 2008-10-31 11:41:12 +0000 |
commit | ac2e992305d0840ff0f82403b017fd60a8bbe0e6 (patch) | |
tree | fc72085412e1b7c00c300c1e6049e289a6f56d92 /remux | |
parent | c364a3396d155efa153cdc183591f7e5fff3d1b7 (diff) | |
download | vdr-plugin-streamdev-ac2e992305d0840ff0f82403b017fd60a8bbe0e6.tar.gz vdr-plugin-streamdev-ac2e992305d0840ff0f82403b017fd60a8bbe0e6.tar.bz2 |
Improved externremux script termination (#455)
Diffstat (limited to 'remux')
-rw-r--r-- | remux/extern.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/remux/extern.c b/remux/extern.c index 7d6307b..c5f35de 100644 --- a/remux/extern.c +++ b/remux/extern.c @@ -27,7 +27,7 @@ public: cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter): m_ResultBuffer(ResultBuffer), m_Active(false), - m_Process(0), + m_Process(-1), m_Inpipe(0), m_Outpipe(0) { @@ -67,8 +67,12 @@ cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter): close(i); //close all dup'ed filedescriptors std::string cmd = std::string(opt_remux) + " " + Parameter; - execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL); - _exit(-1); + if (execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL) == -1) { + esyslog("streamdev-server: externremux script '%s' execution failed: %m", cmd.c_str()); + _exit(-1); + } + // should never be reached + _exit(0); } close(inpipe[0]); @@ -83,16 +87,31 @@ cTSExt::~cTSExt() m_Active = false; Cancel(3); if (m_Process > 0) { + // close pipes close(m_Outpipe); close(m_Inpipe); - kill(m_Process, SIGTERM); - for (int i = 0; waitpid(m_Process, NULL, WNOHANG) == 0; i++) { - if (i == 20) { - esyslog("streamdev-server: externremux process won't stop - killing it"); - kill(m_Process, SIGKILL); + // signal and wait for termination + if (kill(m_Process, SIGINT) < 0) { + esyslog("streamdev-server: externremux SIGINT failed: %m"); + } + 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); } - 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; } } |