views:

22

answers:

1

I'm using sigprocmask as follows:

void mask(){
    sigset_t new_set,old_set;
    sigemptyset(&new_set);
    sigaddset(&new_set,SIGALRM);
    sigprocmask(SIG_BLOCK, &new_set, &old_set);
}

and to my surprise a function which prints a big list somehow gets interrupted by the signal, even though I invoke mask() at its beginning. It looks as if mask fails, since my function doesn't invoke any other functions and therefore nowhere in its run should an unmask() happen. What can cause sigprocmask to fail?

+1  A: 

From the POSIX spec, sigprocmask() returns -1 and sets errno accoringly if it fails. If the code that you posted is the code you are using, you obviously aren't checking to see if it succeeded.

If sigprocmask() is successful, and it is indeed SIGALRM that is interrupting the function that is calling mask(), there is a very good chance that something within that function is handling that signal differently.

The other thing you can do is raise(SIGALRM) immediately after calling mask(), if its ignored, then some other function below that is changing the behavior.

As bmargulies noted in comments (that probably should have been an answer), you can use strace to see if that is indeed the case, coupled with ltrace if applicable to watch it step through library calls.

This is not at all uncommon when you work with libraries that are rude when it comes to installing handlers (e.g. checking to see if a signal is ignored, or handled elsewhere prior to modifying the behavior).

Tim Post