Hi guys - got some questions... hope something helpfull will come out!!! I just want to catch every signal that can be caught and print some info by using only one handler.
I use the sigaction() function and only one instance of a sigaction struct as an argument to the sigaction() function.
1) If sigset_t sigaction.sa_mask is empty, things seem to work fine when i send signals to my process from the command line. However the shell sends an additional SIGCONT to my process for every signal that i send. Why is this happening?
2) If sigset_t sigaction.sa_mask is filled (meaning - from my point of view
- that all signals should block while sig_handler's body is being executed) i get weird results. For example the scheduler (pid=0) is repeatedly sending a SIGBUS signal to my process. Why is this happening?
Thanx in advance, please have a look at the code...
P.S. This is a simplified version of the source code. In fact the program is multi-threaded. Anyway considering just one thread of execution, would this be right?
//----------------------------------------------------------------------------------
void sig_handler(int sig, siginfo_t * info, void * context)
{
FILE *f= fopen("signal_trap", "a");
if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGCHLD || sig == SIGTRAP || sig == SIGPOLL)
fprintf(f, "Signal = %d, subcode = %d, pid = %d, uid = %d, address = %p, errno = %d\n", sig, info->si_code, info->si_pid, info->si_uid, info->si_addr, info->si_errno);
else
fprintf(f, "Signal = %d, pid = %d, uid = %d, address = %p, errno = %d\n", sig, info->si_pid, info->si_uid, info->si_addr, info->si_errno);
fprintf(f, "\n");
fclose(f);
}
//----------------------------------------------------------------------------------
int main()
{
struct sigaction act;
sigemptyset(&act.sa_mask); // or sigfillset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = sig_handler;
sigaction(SIGABRT, &act, 0);
sigaction(SIGALRM, &act, 0);
sigaction(SIGFPE, &act, 0);
sigaction(SIGHUP, &act, 0);
sigaction(SIGILL, &act, 0);
sigaction(SIGINT, &act, 0);
sigaction(SIGPIPE, &act, 0);
// blah blah blah - all available signals use struct sigaction act
return 0;
}
//----------------------------------------------------------------------------------