mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
posix: Fix system blocks SIGCHLD erroneously [BZ #30163]
Fix bug that SIGCHLD is erroneously blocked forever in the following
scenario:
1. Thread A calls system but hasn't returned yet
2. Thread B calls another system but returns
SIGCHLD would be blocked forever in thread B after its system() returns,
even after the system() in thread A returns.
Although POSIX does not require, glibc system implementation aims to be
thread and cancellation safe. This bug was introduced in
5fb7fc9635
when we moved reverting signal
mask to happen when the last concurrently running system returns,
despite that signal mask is per thread. This commit reverts this logic
and adds a test.
Signed-off-by: Adam Yi <ayi@janestreet.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
committed by
Adhemerval Zanella
parent
969e9733c7
commit
436a604b7d
@@ -37,6 +37,7 @@
|
||||
#include <error.h>
|
||||
|
||||
#include <support/support.h>
|
||||
#include <support/timespec.h>
|
||||
|
||||
/* Design considerations
|
||||
|
||||
@@ -169,6 +170,32 @@ kill_func (char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Emulate the "/bin/sleep" command. No suffix support. Options are
|
||||
ignored. */
|
||||
static int
|
||||
sleep_func (char **argv)
|
||||
{
|
||||
if (argv[0] == NULL)
|
||||
{
|
||||
fprintf (stderr, "sleep: missing operand\n");
|
||||
return 1;
|
||||
}
|
||||
char *endptr = NULL;
|
||||
double sec = strtod (argv[0], &endptr);
|
||||
if (endptr == argv[0] || errno == ERANGE || sec < 0)
|
||||
{
|
||||
fprintf (stderr, "sleep: invalid time interval '%s'\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
struct timespec ts = dtotimespec (sec);
|
||||
if (nanosleep (&ts, NULL) < 0)
|
||||
{
|
||||
fprintf (stderr, "sleep: failed to nanosleep: %s\n", strerror (errno));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is a list of all the built-in commands we understand. */
|
||||
static struct {
|
||||
const char *name;
|
||||
@@ -179,6 +206,7 @@ static struct {
|
||||
{ "cp", copy_func },
|
||||
{ "exit", exit_func },
|
||||
{ "kill", kill_func },
|
||||
{ "sleep", sleep_func },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user