From f5843f013463ebcfcd7d2ca172bc75f893576926 Mon Sep 17 00:00:00 2001 From: empathicqubit Date: Sun, 1 Jan 2023 02:18:00 +0100 Subject: [PATCH] Add interrupt handler to bridge --- src/tibridge.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tibridge.c b/src/tibridge.c index b6b55b4..778100a 100644 --- a/src/tibridge.c +++ b/src/tibridge.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "common/utils.h" @@ -85,7 +86,23 @@ void retry_recv(uint8_t* recv, int recvCount) { fflush(stdout); } +void cleanup() { + if(cable_handle) { + ticables_cable_close(cable_handle); + ticables_handle_del(cable_handle); + } + ticables_library_exit(); +} + +void handle_sigint(int code) { + cleanup(); +} + int main(int argc, char *argv[]) { + struct sigaction sa; + sa.sa_handler = handle_sigint; + sigaction(SIGINT, &sa, NULL); + // z88dk-gdb doesn't like the ACKs -/+, so we just hide them int handle_acks = 1;