From 7496c9f18349fbbd9244339f2cf59d94321ecb9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 14 Sep 2022 13:37:35 +0100 Subject: [PATCH] Fix: lttng-ust-comm: wait on wrong child process MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The code currently assumes that the forked process is the only child process at that point in time. However, there can be unreaped child processes as reported in the original bug. From wait(3), as currently used, "status is requested for any child process." Using the pid explicitly ensures a wait on the expected child process. More context is available at: https://bugs.lttng.org/issues/1359 Fixes #1359 Signed-off-by: Jérémie Galarneau Signed-off-by: Mathieu Desnoyers Change-Id: I8a4621d79c61f7dfefde5c2b94bdee9752e1973d --- liblttng-ust/lttng-ust-comm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 7b353c85..716795e0 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -1293,14 +1293,14 @@ open_write: pid = fork(); URCU_TLS(lttng_ust_nest_count)--; if (pid > 0) { - int status; + int status, wait_ret; /* * Parent: wait for child to return, in which case the * shared memory map will have been created. */ - pid = wait(&status); - if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { + wait_ret = waitpid(pid, &status, 0); + if (wait_ret < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { wait_shm_fd = -1; goto end; } -- 2.34.1