Fix restore of child handler in restoreChildHandler()
[libasyncio] / 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