Fix: use non block waitpid to lookup child state
authorDavid Goulet <dgoulet@efficios.com>
Thu, 21 Nov 2013 18:02:40 +0000 (13:02 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 22 Nov 2013 19:25:19 +0000 (14:25 -0500)
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>
src/bin/lttng-sessiond/main.c

index 8aea0e77c840e38f3a05b117064fbc21f1f900e9..67ecc5228a194c7b6edda49431f0f20dcfa3ea16 100644 (file)
@@ -4580,6 +4580,18 @@ static int daemonize(void)
                 * 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);
                }
 
This page took 0.028495 seconds and 4 git commands to generate.