aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Domke <tmbinc@elitedvb.net>2007-12-16 20:34:49 +0000
committerFelix Domke <tmbinc@elitedvb.net>2007-12-16 20:34:49 +0000
commita5676fcdcfe2ed60d3e5ff933f210ba49df9437e (patch)
tree5da08d8804a3f1ad2843fe82d906703886a88311
parent96a171a3f8daf3ebae2990c1bfa10bdeb0c5e87c (diff)
downloadenigma2-a5676fcdcfe2ed60d3e5ff933f210ba49df9437e.tar.gz
enigma2-a5676fcdcfe2ed60d3e5ff933f210ba49df9437e.zip
patch by Pieter Grimmerink: -call waitpid on the child, after it completes. This avoids zombies.
-rw-r--r--lib/base/console.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/base/console.cpp b/lib/base/console.cpp
index 3f73fba1..1e391e17 100644
--- a/lib/base/console.cpp
+++ b/lib/base/console.cpp
@@ -5,6 +5,8 @@
#include <signal.h>
#include <errno.h>
#include <poll.h>
+#include <sys/types.h>
+#include <sys/wait.h>
int bidirpipe(int pfd[], char *cmd , char *argv[])
{
@@ -222,7 +224,11 @@ void eConsoleAppContainer::kill()
{
eDebug("user kill(SIGKILL) console App");
killstate=-1;
- ::kill(pid, SIGKILL);
+ /*
+ * Use a negative pid value, to signal the whole process group
+ * ('pid' might not even be running anymore at this point)
+ */
+ ::kill(-pid, SIGKILL);
closePipes();
}
while( outbuf.size() ) // cleanup out buffer
@@ -242,7 +248,11 @@ void eConsoleAppContainer::sendCtrlC()
if ( killstate != -1 && pid != -1 )
{
eDebug("user send SIGINT(Ctrl-C) to console App");
- ::kill(pid, SIGINT);
+ /*
+ * Use a negative pid value, to signal the whole process group
+ * ('pid' might not even be running anymore at this point)
+ */
+ ::kill(-pid, SIGINT);
}
}
@@ -301,7 +311,20 @@ void eConsoleAppContainer::readyRead(int what)
{
eDebug("child has terminated");
closePipes();
- /*emit*/ appClosed(killstate);
+ int childstatus;
+ int retval = killstate;
+ /*
+ * We have to call 'wait' on the child process, in order to avoid zombies.
+ * Also, this gives us the chance to provide better exit status info to appClosed.
+ */
+ if (::waitpid(pid, &childstatus, 0) > 0)
+ {
+ if (WIFEXITED(childstatus))
+ {
+ retval = WEXITSTATUS(childstatus);
+ }
+ }
+ /*emit*/ appClosed(retval);
}
}