From bb7e707e2759ea3f14af644682355ab3ef15802a Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Mon, 30 Dec 2024 21:24:17 +0100 Subject: [PATCH] simulator: async-signal safety printf is not async-signal safe, see https://docs.oracle.com/cd/E19455-01/806-5257/gen-26/index.html --- test/simulator/simulator.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; }