Skip to content

Commit

Permalink
Linux: fix handling of zombie processes
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed May 25, 2013
1 parent 32b1a5e commit 029ca26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 10 additions & 1 deletion xbmc/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,15 @@ bool CUtil::Command(const CStdStringArray& arrArgs, bool waitExit)
int n = 0;
if (child == 0)
{
if (!waitExit)
{
// fork again in order not to leave a zombie process
child = fork();
if (child == -1)
_exit(2);
else if (child != 0)
_exit(0);
}
close(0);
close(1);
close(2);
Expand All @@ -1646,7 +1655,7 @@ bool CUtil::Command(const CStdStringArray& arrArgs, bool waitExit)
}
else
{
if (waitExit) waitpid(child, &n, 0);
waitpid(child, &n, 0);
}

return (waitExit) ? (WEXITSTATUS(n) == 0) : true;
Expand Down
7 changes: 0 additions & 7 deletions xbmc/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ int main(int argc, char* argv[])
if (setrlimit(RLIMIT_CORE, &rlim) == -1)
CLog::Log(LOGDEBUG, "Failed to set core size limit (%s)", strerror(errno));
#endif
// Prevent child processes from becoming zombies on exit if not waited upon. See also Util::Command
struct sigaction sa;
memset(&sa, 0, sizeof(sa));

sa.sa_flags = SA_NOCLDWAIT;
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL);
#endif
setlocale(LC_NUMERIC, "C");
g_advancedSettings.Initialize();
Expand Down

0 comments on commit 029ca26

Please sign in to comment.