Fix blocking SIGCHLD

Unblocking the `SIGCHLD` signal before the child process completes
prevents the `callback()` from being ever called.

This commit makes the blocking `SIGCHLD` once for the whole main process
life by moving the corresponding code block to the main().

Tested: `callback()` now called when the child process completes.

Change-Id: I553c683e5dfcbc0b33c72aa2d7b394f689772966
Signed-off-by: Alexander Filippov <a.filippov@yadro.com>
diff --git a/dump_manager.cpp b/dump_manager.cpp
index c87ec8f..a42fce2 100644
--- a/dump_manager.cpp
+++ b/dump_manager.cpp
@@ -45,29 +45,6 @@
     // Get Dump size.
     auto size = getAllowedSize();
 
-    // Blocking SIGCHLD is needed for calling sd_event_add_child
-    sigset_t mask;
-    if (sigemptyset(&mask) < 0)
-    {
-        log<level::ERR>("Unable to initialize signal set",
-                        entry("ERRNO=%d", errno));
-        throw std::runtime_error("Unable to initialize signal set");
-    }
-
-    if (sigaddset(&mask, SIGCHLD) < 0)
-    {
-        log<level::ERR>("Unable to add signal to signal set",
-                        entry("ERRNO=%d", errno));
-        throw std::runtime_error("Unable to add signal to signal set");
-    }
-
-    // Block SIGCHLD first, so that the event loop can handle it
-    if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0)
-    {
-        log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno));
-        throw std::runtime_error("Unable to block signal");
-    }
-
     pid_t pid = fork();
 
     if (pid == 0)
@@ -101,12 +78,6 @@
                             entry("RC=%d", rc));
             elog<InternalFailure>();
         }
-        if (sigprocmask(SIG_UNBLOCK, &mask, NULL) < 0)
-        {
-            log<level::ERR>("Unable to unblock signal",
-                            entry("ERRNO=%d", errno));
-            throw std::runtime_error("Unable to unblock signal");
-        }
     }
     else
     {
diff --git a/dump_manager_main.cpp b/dump_manager_main.cpp
index fe1a147..787bd12 100644
--- a/dump_manager_main.cpp
+++ b/dump_manager_main.cpp
@@ -28,6 +28,29 @@
     phosphor::dump::EventPtr eventP{event};
     event = nullptr;
 
+    // Blocking SIGCHLD is needed for calling sd_event_add_child
+    sigset_t mask;
+    if (sigemptyset(&mask) < 0)
+    {
+        log<level::ERR>("Unable to initialize signal set",
+                        entry("ERRNO=%d", errno));
+        return EXIT_FAILURE;
+    }
+
+    if (sigaddset(&mask, SIGCHLD) < 0)
+    {
+        log<level::ERR>("Unable to add signal to signal set",
+                        entry("ERRNO=%d", errno));
+        return EXIT_FAILURE;
+    }
+
+    // Block SIGCHLD first, so that the event loop can handle it
+    if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
+    {
+        log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno));
+        return EXIT_FAILURE;
+    }
+
     // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
     sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH);
     bus.request_name(DUMP_BUSNAME);