utils: Check pending signals to ensure default handler completion

Default signal handler is invoked by deregistering the custom
handler. After default handler has executed, custom handler
should be re-registered. Since sigqueue is non-blocking, it
is not known when default handler has executed. We add a delay
for re-registration to let the default handler finish. However,
if we re-register custom handler before default handler has
been invoked, this leads to a recursive loop where custom
handler is called again. Avoid such a recursive loop and related
race conditions by checking for pending signals with the kernel
and do not re-register custom handler if signal is still in the
queue.

Change-Id: Ic12a47241fa76c51be0f4c8b9938d7118024b803
2 files changed