Skip to content
Snippets Groups Projects
Commit c1941e95 authored by Eitan Adler's avatar Eitan Adler
Browse files

Fix bug with signal handling in catch.c

Signal handlers might be called repeatedly. As such they can't call
non-async-safe functions such as printf. Instead set a sentinel and
check for it.
parent 7f9aefbd
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -2,8 +2,10 @@
#include <signal.h>
#include <unistd.h>
 
sig_atomic_t caught_sigint = 0;
void InterruptHandler(int signo) {
printf("Caught SIGINT\n");
caught_sigint = 1;
}
 
int main(int argc, char *argv[]) {
Loading
Loading
@@ -14,7 +16,9 @@ int main(int argc, char *argv[]) {
 
while(1) {
sleep(1);
if (caught_sigint) {
printf("Caught SIGINT\n");
caught_sigint = 0;
}
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment