When daemonizing the session daemon, if the child fails *before* it
could set the recv_child_signal variable that indicates the parent to
exit, the parent process gets in an infinite loop never returning.
This commit fixes that by adding a non blocking waitpid() that monitors
the status of the child so it can exit if the child failed.
Acked-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
* user.
*/
while (!CMM_LOAD_SHARED(recv_child_signal)) {
+ int status;
+ pid_t ret;
+
+ /*
+ * Check if child exists without blocking. If so, we have to stop
+ * this parent process and return an error.
+ */
+ ret = waitpid(pid, &status, WNOHANG);
+ if (ret < 0 || (ret != 0 && WIFEXITED(status))) {
+ /* The child exited somehow or was not valid. */
+ goto error;
+ }
sleep(1);
}