mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
tst-mallocfork2: Fix race condition, use fewer resources
The first SIGUSR1 signal could arrive when sigusr1_sender_pid
was still 0. As a result, kill would send SIGSTOP to the
entire process group. This would cause the test to hang before
printing any output.
This commit also adds a sched_yield to the signal source, so that
it does not flood the parent process with signals it has never a
chance to handle.
Even with these changes, tst-mallocfork2 still fails reliably
after the fix in commit commit 56290d6e76
(Increase fork signal safety for single-threaded processes) is
backed out.
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
still make fork unsafe, even in single-threaded processes. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@ -70,7 +71,9 @@ sigusr1_handler (int signo)
|
||||
signals from the subprocess. */
|
||||
if (sigusr1_received)
|
||||
return;
|
||||
if (kill (sigusr1_sender_pid, SIGSTOP) != 0)
|
||||
/* sigusr1_sender_pid might not be initialized in the parent when
|
||||
the first SIGUSR1 signal arrives. */
|
||||
if (sigusr1_sender_pid > 0 && kill (sigusr1_sender_pid, SIGSTOP) != 0)
|
||||
{
|
||||
write_message ("error: kill (SIGSTOP)\n");
|
||||
abort ();
|
||||
@ -123,6 +126,9 @@ signal_sender (int signo, bool sleep)
|
||||
}
|
||||
if (sleep)
|
||||
usleep (1 * 1000 * 1000);
|
||||
else
|
||||
/* Reduce the rate at which we send signals. */
|
||||
sched_yield ();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user