From 83dd64f68a77bd01d550ad79d14ea03a8af91f16 Mon Sep 17 00:00:00 2001 From: schmirl Date: Thu, 5 Oct 2006 06:03:23 +0000 Subject: [PATCH] - collect terminated externremux.sh processes (#136) - avoid fd leaks when we fail to spawn externremux.sh --- remux/extern.c | 23 ++++++++++++++++++++--- 1 file 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 #include +#include #include +#include 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)