Fix restore of child handler in restoreChildHandler()
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 4 May 2017 07:31:53 +0000 (09:31 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 4 May 2017 07:31:53 +0000 (09:31 +0200)
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.

asyncio/async_process.cpp

index f93e320..a5f3285 100644 (file)
@@ -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