I am working on a tool handling a massive amount of signals (with different signums) with
I need to handle the case, if a new signal is coming, while the previous was in a signal handler. Thus, I need to be able to handle the following "stack":
- normal flow of the process
- handler of signal1
- handler of signal2
- ...possibly further signal handlers...
(Afaik there is no real stack, because signal handlers run in their own context, but this is how I can illustrate my question.)
I am using the glibc2 api.
The problem is not hopeless (I can pass the signal infos to reentrant data structures in the main process to be processed later, from the main execution flow), but I need a reliable way to find out from a handler, if it is the first on the "stack" or not.
Masking signals is not okay, minimizing the loss of signals (f.e. from conflation) is a top priority.
I need reliable way. Using a global sigatomic_t as spinlock is also problematic, because I can't guarantee that a new signal isn't coming just after the beginning of signal1 handler (yet before the try to acquire the lock).
After digging a lot in manuals and glibc docs, I didn't find any reliable way to for a signal handler to find out, if he is the first or not. Is it somehow possible?