aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-05-21 01:37:38 +0200
committerGitHub <[email protected]>2021-05-20 16:37:38 -0700
commite72383825bbd48524bef19feb9893cdb05107f15 (patch)
tree809aec978c763dd2cb2cc22f4f534f1834785296 /cmd
parent0b1b66b4735f13d826ece675ea5568a7d3ca316c (diff)
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 <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #12086
Diffstat (limited to 'cmd')
-rw-r--r--cmd/raidz_test/raidz_test.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/cmd/raidz_test/raidz_test.c b/cmd/raidz_test/raidz_test.c
index 9a8be549c..c1610a8d1 100644
--- a/cmd/raidz_test/raidz_test.c
+++ b/cmd/raidz_test/raidz_test.c
@@ -37,11 +37,11 @@
static int *rand_data;
raidz_test_opts_t rto_opts;
-static char gdb[256];
-static const char gdb_tmpl[] = "gdb -ex \"set pagination 0\" -p %d";
+static char pid_s[16];
static void sig_handler(int signo)
{
+ int old_errno = errno;
struct sigaction action;
/*
* Restore default action and re-raise signal so SIGSEGV and
@@ -52,10 +52,19 @@ static void sig_handler(int signo)
action.sa_flags = 0;
(void) sigaction(signo, &action, NULL);
- if (rto_opts.rto_gdb)
- if (system(gdb)) { }
+ if (rto_opts.rto_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);
+ errno = old_errno;
}
static void print_opts(raidz_test_opts_t *opts, boolean_t force)
@@ -978,8 +987,8 @@ main(int argc, char **argv)
struct sigaction action;
int err = 0;
- /* init gdb string early */
- (void) sprintf(gdb, gdb_tmpl, getpid());
+ /* init gdb pid string early */
+ (void) sprintf(pid_s, "%d", getpid());
action.sa_handler = sig_handler;
sigemptyset(&action.sa_mask);