From: Thomas Jarosch Date: Thu, 4 May 2017 07:31:53 +0000 (+0200) Subject: Fix restore of child handler in restoreChildHandler() X-Git-Url: http://developer.intra2net.com/git/?p=libasyncio;a=commitdiff_plain;h=a3c5225a5e2cbeee488b9c878f39bb9d26236761 Fix restore of child handler in restoreChildHandler() SIG_DFL is 0 and therefore the code in restoreChildHandler() was never executed. Fix it by introducing an extra variable that keeps the state if the child handler was installed or not. --- diff --git a/asyncio/async_process.cpp b/asyncio/async_process.cpp index f93e320..a5f3285 100644 --- a/asyncio/async_process.cpp +++ b/asyncio/async_process.cpp @@ -74,6 +74,9 @@ namespace config /// the previous handler for the child signal (SIGCHLD) void (*oldChildHandler)(int) = NULL; +/// indicates if we installed our own signal handler or not +bool installedChildHandler = false; + /// method pointer for activating process manager void (ProcessManager::*_activate_manager)(); @@ -226,7 +229,7 @@ namespace AsyncIo */ bool installChildHandler() { - if (oldChildHandler) + if (installedChildHandler) { // already installed return true; @@ -240,9 +243,10 @@ bool installChildHandler() oldChildHandler = signal( Signal::CHLD, handleSigChild ); if (oldChildHandler == SIG_ERR) { - oldChildHandler= NULL; + oldChildHandler = NULL; return false; } + installedChildHandler = true; return true; } // eo installChildHandler @@ -253,17 +257,16 @@ bool installChildHandler() */ bool restoreChildHandler() { - if (!oldChildHandler) - { + if (!installedChildHandler) return false; - } - void(*res)(int) = signal( Signal::CHLD, oldChildHandler); + void(*res)(int) = signal( Signal::CHLD, oldChildHandler ); if (res == SIG_ERR) - { return false; - } - oldChildHandler= NULL; + + oldChildHandler = NULL; + installedChildHandler = false; + return true; } // eo restoreChildHandler