davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.01k stars 250 forks source link

unsafe fileserver.c example (about Unix signals) #278

Open bstarynk opened 3 years ago

bstarynk commented 3 years ago

In commit 2b3b230b79ecae119b7eb847f2 the fileserver.c example has unsafe code about signal (near line 154, calling signal(2) ...)

Read both signal(7) and signal-safety(7).

We might take inspiration from Qt5 Unix signal handling, that is use the famous pipe(7) to self trick. Then all the event loops should also poll(2) on that pipe (reading end) and the signal handler would write(2) at least a byte on that pipe (writing end).

We could also decide to declare some extern volatile sigatomic_t onion_should_stop; variable and have signal handlers setting onion_should_stop and have all the event loops testing that variable repeatedly.