From 626aa84814bdc13524a12974be43064e6ae408ae Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Fri, 17 Feb 2023 17:29:16 +0100 Subject: [PATCH] Stop the emulation on ^C and finish the traces --- src/emu/ovniemu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/emu/ovniemu.c b/src/emu/ovniemu.c index eeba848..b7013b2 100644 --- a/src/emu/ovniemu.c +++ b/src/emu/ovniemu.c @@ -1,8 +1,18 @@ #include "emu.h" #include +#include #include "common.h" +static volatile int run = 1; + +static void stop_emulation(int dummy) +{ + UNUSED(dummy); + run = 0; + signal(SIGINT, SIG_DFL); +} + int main(int argc, char *argv[]) { @@ -21,9 +31,11 @@ main(int argc, char *argv[]) if (emu_connect(emu) != 0) die("emu_connect failed\n"); + signal(SIGINT, stop_emulation); + err("emulation starts"); int ret = 0; - while ((ret = emu_step(emu)) == 0); + while (run && (ret = emu_step(emu)) == 0); if (ret < 0) { err("emu_step failed"); @@ -34,6 +46,9 @@ main(int argc, char *argv[]) ret = 0; } + if (run == 0) + err("stopping emulation by user (^C again to abort)"); + if (emu_finish(emu) != 0) { err("emu_finish failed"); ret = 1;