gbacktrace: Correctly wait for children on Unix

The WIF* macros are supposed to be used with the status, not the pid.

Also, only check the status if no error occurred, otherwise the value
might be uninitialized. If an unrecoverable error occurs, break the
loop (could happen if SIGCHLD is ignored).
This commit is contained in:
Tobias Stoeckmann
2025-07-07 20:14:56 +02:00
parent d0f31c23d5
commit d30bba26ea

View File

@@ -290,7 +290,13 @@ g_on_error_stack_trace (const gchar *prg_name)
while (1)
{
pid_t retval = waitpid (pid, &status, 0);
if (WIFEXITED (retval) || WIFSIGNALED (retval))
if (retval == -1)
{
if (errno == EAGAIN || errno == EINTR)
continue;
break;
}
else if (WIFEXITED (status) || WIFSIGNALED (status))
break;
}
#else