Block SIGCHLD before calling sd_event_add_child
Based on the documentation sd_event_add_child will return
EBUSY if the SIGCHLD is not blocked, so adding the code
to block the SIGCHLD
Testing:
Without the patch CreateDump will fail and with the fix
the CreateDump is working
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I33f250bdb472dca08588c48ffa663d561bc2bc84
diff --git a/dump_manager.cpp b/dump_manager.cpp
index a42fce2..c87ec8f 100644
--- a/dump_manager.cpp
+++ b/dump_manager.cpp
@@ -45,6 +45,29 @@
// 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)
@@ -78,6 +101,12 @@
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
{