I am trying to trap a SIGSEGV (also SIGBUS, SIGILL and SIGFPE, but I have not even managed to generate those yet :-( ).
I can easily get the program to produce a message "Segmentation Violation" on stderr, but noway can I catch it before getting that message.
I have written
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGUSR2);
sigaddset(&set, SIGTERM);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGSEGV);
sigaddset(&set, SIGBUS);
sigaddset(&set, SIGILL);
sigaddset(&set, SIGFPE);
sigaddset(&set, SIGSYS);
and I have created a pthread which contains
sigwait(&set, &signal);
printf("Display signal %d\n", signal);
switch (signal) {
case SIGSEGV:
case SIGBUS:
case SIGILL:
case SIGFPE:
case SIGSYS:
fatal("Heat failed: %s", strerror(errno));
case SIGTERM:
case SIGINT:
warn("Heat terminated");
exit(0);
default:
fatal("Unanticipated signal %d", signal);
}
but the SIGSEGV is never caught (though SIGTERM is caught fine, as is an explicit "kill -s SEGV").
How can I fix this? 'warn' and 'fatal' do what you would expect, and 'fatal' calls 'exit(-1).
Note also that arms tend not to raise SIGFPE even if you do the most terrible divisions by zero. Apparently there is now a linux patch to fix this.
Thursday, May 17, 2012
[nslu2-linux] Catching SIGSEGV
__._,_.___
.
__,_._,___
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment