From 08d68fcf3eaf7dfd01c0a3e52a126804c5404754 Mon Sep 17 00:00:00 2001 From: Aomx <julian.cordes@gmail.com> Date: Wed, 30 Sep 2015 14:11:07 +0200 Subject: [PATCH] added interrupt_handler at run.c --- gtests/net/packetdrill/run.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gtests/net/packetdrill/run.c b/gtests/net/packetdrill/run.c index 8a40af7b..5f44f997 100644 --- a/gtests/net/packetdrill/run.c +++ b/gtests/net/packetdrill/run.c @@ -64,6 +64,15 @@ */ const int MAX_SPIN_USECS = 20; +struct state *state = NULL; + +void interrupt_handler(int signal_number) { + if (state != NULL) + state_free(state); + + die("interrupted"); +} + struct state *state_new(struct config *config, struct script *script, struct netdev *netdev) @@ -146,7 +155,7 @@ void state_free(struct state *state) run_unlock(state); if (pthread_mutex_destroy(&state->mutex) != 0) die_perror("pthread_mutex_destroy"); - + memset(state, 0, sizeof(*state)); /* paranoia to help catch bugs */ free(state); } @@ -496,9 +505,12 @@ static s64 schedule_start_time_usecs(void) void run_script(struct config *config, struct script *script) { char *error = NULL; - struct state *state = NULL; struct netdev *netdev = NULL; struct event *event = NULL; + + if (signal(SIGINT, interrupt_handler) == SIG_ERR) { + die("could not set up interrupt handler!"); + } DEBUGP("run_script: running script\n"); -- GitLab