diff --git a/test/simulator/simulator.c b/test/simulator/simulator.c index aa9c8ab94..1f9d69b34 100644 --- a/test/simulator/simulator.c +++ b/test/simulator/simulator.c @@ -33,6 +33,7 @@ #include #include #include +#include #include static const char* _simulator_version = "1.0.0"; @@ -42,6 +43,7 @@ static const char* _simulator_version = "1.0.0"; int data_len; int commfd; +static volatile sig_atomic_t sigint_called = false; static int sockfd; int get_usb_message_socket(uint8_t* input) @@ -72,7 +74,7 @@ void simulate_firmware_execution(const uint8_t* input) static void _int_handler(int _signum) { - printf("\n\nGot Ctrl-C, exiting\n\n"); + sigint_called = true; close(sockfd); } @@ -158,6 +160,9 @@ int main(int argc, char* argv[]) while (1) { if ((commfd = accept(sockfd, (struct sockaddr*)&serv_addr, (socklen_t*)&serv_addr_len)) < 0) { + if (sigint_called) { + printf("\nGot Ctrl-C, exiting\n"); + } perror("accept"); return 1; }