summaryrefslogtreecommitdiff
path: root/remux
diff options
context:
space:
mode:
authorschmirl <schmirl>2006-10-05 06:03:23 +0000
committerschmirl <schmirl>2006-10-05 06:03:23 +0000
commit83dd64f68a77bd01d550ad79d14ea03a8af91f16 (patch)
tree3caab582bb4f3880a62b2fbe8e97030f3447fe7f /remux
parent06265bab7bd5dea2e561a1c62b39ebcf36b164e3 (diff)
downloadvdr-plugin-streamdev-83dd64f68a77bd01d550ad79d14ea03a8af91f16.tar.gz
vdr-plugin-streamdev-83dd64f68a77bd01d550ad79d14ea03a8af91f16.tar.bz2
- collect terminated externremux.sh processes (#136)
- avoid fd leaks when we fail to spawn externremux.sh
Diffstat (limited to 'remux')
-rw-r--r--remux/extern.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/remux/extern.c b/remux/extern.c
index 50f103a..b1857f8 100644
--- a/remux/extern.c
+++ b/remux/extern.c
@@ -2,7 +2,9 @@
#include "server/streamer.h"
#include <vdr/tools.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <signal.h>
+#include <unistd.h>
class cTSExt: public cThread {
private:
@@ -38,11 +40,17 @@ cTSExt::cTSExt(cRingBufferLinear *ResultBuffer):
if (pipe(outpipe) == -1) {
LOG_ERROR_STR("pipe failed");
+ close(inpipe[0]);
+ close(inpipe[1]);
return;
}
if ((m_Process = fork()) == -1) {
LOG_ERROR_STR("fork failed");
+ close(inpipe[0]);
+ close(inpipe[1]);
+ close(outpipe[0]);
+ close(outpipe[1]);
return;
}
@@ -74,9 +82,18 @@ cTSExt::~cTSExt()
{
m_Active = false;
Cancel(3);
- close(m_Outpipe);
- close(m_Inpipe);
- kill(m_Process, SIGTERM);
+ if (m_Process > 0) {
+ 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);
+ }
+ cCondWait::SleepMs(100);
+ }
+ }
}
void cTSExt::Action(void)