onion icon indicating copy to clipboard operation
onion copied to clipboard

unsafe fileserver.c example (about Unix signals)

Open bstarynk opened this issue 4 years ago • 0 comments

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.

bstarynk avatar Nov 21 '20 07:11 bstarynk