Commit f014cdaf authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Improve signal/sigaction wrapper

parent 6c948b6d
...@@ -173,26 +173,51 @@ int rand (void) ...@@ -173,26 +173,51 @@ int rand (void)
/** Signals **/ /** Signals **/
#include <signal.h> #include <signal.h>
static bool blocked_signal (int num)
{
switch (num)
{
case SIGINT:
case SIGHUP:
case SIGQUIT:
case SIGTERM:
case SIGPIPE:
case SIGCHLD:
return true;
}
return false;
}
void (*signal (int signum, void (*handler) (int))) (int) void (*signal (int signum, void (*handler) (int))) (int)
{ {
if (override) if (override)
{ {
const char *msg = "Error"; if (handler != SIG_IGN && handler != SIG_DFL)
goto error;
if ((signum == SIGPIPE && handler == SIG_IGN) if (!blocked_signal (signum))
|| (signum != SIGPIPE && handler == SIG_DFL)) goto error;
/* Same settings we already use */ /* For our blocked signals, the handler won't matter much... */
msg = "Warning"; LOG("Warning", "%d, %p", signum, handler);
LOG(msg, "%d, %p", signum, handler);
} }
return CALL(signal, signum, handler); return CALL(signal, signum, handler);
error:
LOG("Blocked", "%d, %p", signum, handler);
return SIG_DFL;
} }
int sigaction (int signum, const struct sigaction *act, struct sigaction *old) int sigaction (int signum, const struct sigaction *act, struct sigaction *old)
{ {
if (act != NULL) if (override && act != NULL)
LOG("Error", "%d, %p, %p", signum, act, old); {
if ((act->sa_flags & SA_SIGINFO)
|| (act->sa_handler != SIG_IGN && act->sa_handler != SIG_DFL))
goto error;
LOG("Warning", "%d, %p, %p", signum, act, old);
}
return CALL(sigaction, signum, act, old); return CALL(sigaction, signum, act, old);
error:
LOG("Blocked", "%d, %p, %p", signum, act, old);
return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment