Skip to content

Commit

Permalink
Merge pull request #1353 from NickeZ/nickez/simulator-signal-safety
Browse files Browse the repository at this point in the history
simulator: async-signal safety
  • Loading branch information
NickeZ authored Jan 8, 2025
2 parents cda3c57 + bb7e707 commit 84301a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/simulator/simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdbool.h>
#include <sys/socket.h>

static const char* _simulator_version = "1.0.0";
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 84301a8

Please sign in to comment.