raidz_test: use only async-signal-safe functions in signal handler
execl*() before glibc 2.24 could allocate, but only if called with at least 1024 arguments, which five isn't errno modification is also fine, so long as we restore it at the end Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12086
This commit is contained in:
parent
0b1b66b473
commit
e72383825b
|
@ -37,11 +37,11 @@
|
||||||
static int *rand_data;
|
static int *rand_data;
|
||||||
raidz_test_opts_t rto_opts;
|
raidz_test_opts_t rto_opts;
|
||||||
|
|
||||||
static char gdb[256];
|
static char pid_s[16];
|
||||||
static const char gdb_tmpl[] = "gdb -ex \"set pagination 0\" -p %d";
|
|
||||||
|
|
||||||
static void sig_handler(int signo)
|
static void sig_handler(int signo)
|
||||||
{
|
{
|
||||||
|
int old_errno = errno;
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
/*
|
/*
|
||||||
* Restore default action and re-raise signal so SIGSEGV and
|
* Restore default action and re-raise signal so SIGSEGV and
|
||||||
|
@ -52,10 +52,19 @@ static void sig_handler(int signo)
|
||||||
action.sa_flags = 0;
|
action.sa_flags = 0;
|
||||||
(void) sigaction(signo, &action, NULL);
|
(void) sigaction(signo, &action, NULL);
|
||||||
|
|
||||||
if (rto_opts.rto_gdb)
|
if (rto_opts.rto_gdb) {
|
||||||
if (system(gdb)) { }
|
pid_t pid = fork();
|
||||||
|
if (pid == 0) {
|
||||||
|
execlp("gdb", "gdb", "-ex", "set pagination 0",
|
||||||
|
"-p", pid_s, NULL);
|
||||||
|
_exit(-1);
|
||||||
|
} else if (pid > 0)
|
||||||
|
while (waitpid(pid, NULL, 0) == -1 && errno == EINTR)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
raise(signo);
|
raise(signo);
|
||||||
|
errno = old_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_opts(raidz_test_opts_t *opts, boolean_t force)
|
static void print_opts(raidz_test_opts_t *opts, boolean_t force)
|
||||||
|
@ -978,8 +987,8 @@ main(int argc, char **argv)
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
/* init gdb string early */
|
/* init gdb pid string early */
|
||||||
(void) sprintf(gdb, gdb_tmpl, getpid());
|
(void) sprintf(pid_s, "%d", getpid());
|
||||||
|
|
||||||
action.sa_handler = sig_handler;
|
action.sa_handler = sig_handler;
|
||||||
sigemptyset(&action.sa_mask);
|
sigemptyset(&action.sa_mask);
|
||||||
|
|
Loading…
Reference in New Issue