From: Andrew Waterman Date: Tue, 23 Jul 2013 01:45:45 +0000 (-0700) Subject: Kill spike when xspike is SIGINTed X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2c87b07a1d43d19acde6c7221bb60a52113e1ea6;p=riscv-isa-sim.git Kill spike when xspike is SIGINTed --- diff --git a/riscv/xspike.cc b/riscv/xspike.cc index fd7c5c8..4331dbe 100644 --- a/riscv/xspike.cc +++ b/riscv/xspike.cc @@ -22,7 +22,6 @@ int main(int argc, char** argv) static bool signal_exit = false; auto handle_signal = [](int) { signal_exit = true; }; - signal(SIGINT, handle_signal); if ((xterm = fork_xterm(&tty_fd)) < 0) { @@ -30,15 +29,22 @@ int main(int argc, char** argv) goto out; } + signal(SIGINT, handle_signal); + if ((spike = fork_spike(tty_fd, argc, argv)) < 0) { fprintf(stderr, "could not open spike\n"); goto close_xterm; } - while (waitpid(spike, &wait_status, 0) < 0 && !signal_exit) - ; - ret = !signal_exit && WIFEXITED(wait_status) ? WEXITSTATUS(wait_status) : -1; + while ((ret = waitpid(spike, &wait_status, 0)) < 0) + if (signal_exit) + break; + + if (ret < 0) // signal_exit + kill(spike, SIGTERM); + else + ret = WIFEXITED(wait_status) ? WEXITSTATUS(wait_status) : -1; close_xterm: kill(-xterm, SIGTERM);