Fix: lttng-ust-comm: wait on wrong child process
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 14 Sep 2022 12:37:35 +0000 (13:37 +0100)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 15 Sep 2022 20:34:31 +0000 (21:34 +0100)
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 <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I8a4621d79c61f7dfefde5c2b94bdee9752e1973d

src/lib/lttng-ust/lttng-ust-comm.c

index 0fe2da466ad1cce241b0b82efd864e651223341e..7903550f5cfc32c599f46ba49e7f6f8d3327615d 100644 (file)
@@ -1584,14 +1584,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;
                }
This page took 0.0257 seconds and 4 git commands to generate.