Skip to content

Commit 84301a8

Browse files
authored
Merge pull request #1353 from NickeZ/nickez/simulator-signal-safety
simulator: async-signal safety
2 parents cda3c57 + bb7e707 commit 84301a8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/simulator/simulator.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <netdb.h>
3434
#include <netinet/in.h>
3535
#include <signal.h>
36+
#include <stdbool.h>
3637
#include <sys/socket.h>
3738

3839
static const char* _simulator_version = "1.0.0";
@@ -42,6 +43,7 @@ static const char* _simulator_version = "1.0.0";
4243
int data_len;
4344
int commfd;
4445

46+
static volatile sig_atomic_t sigint_called = false;
4547
static int sockfd;
4648

4749
int get_usb_message_socket(uint8_t* input)
@@ -72,7 +74,7 @@ void simulate_firmware_execution(const uint8_t* input)
7274

7375
static void _int_handler(int _signum)
7476
{
75-
printf("\n\nGot Ctrl-C, exiting\n\n");
77+
sigint_called = true;
7678
close(sockfd);
7779
}
7880

@@ -158,6 +160,9 @@ int main(int argc, char* argv[])
158160
while (1) {
159161
if ((commfd = accept(sockfd, (struct sockaddr*)&serv_addr, (socklen_t*)&serv_addr_len)) <
160162
0) {
163+
if (sigint_called) {
164+
printf("\nGot Ctrl-C, exiting\n");
165+
}
161166
perror("accept");
162167
return 1;
163168
}

0 commit comments

Comments
 (0)