From: David Goulet Date: Thu, 21 Nov 2013 18:02:40 +0000 (-0500) Subject: Fix: use non block waitpid to lookup child state X-Git-Tag: v2.4.0-rc2~37 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=077df0b372f77833c1de2dd9f534dec9e75696de;hp=dd2c2a1b8ad6c0fb516f7e7c1bf1adfa6b93b8e6 Fix: use non block waitpid to lookup child state 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 Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 8aea0e77c..67ecc5228 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -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); }