Pregunta

Estoy usando sigprocmask de la siguiente manera:

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

y para mi sorpresa una función que imprime una gran lista de alguna manera se interrumpe por la señal, a pesar de que invoco máscara () en su comienzo. Parece como si falla la máscara, ya que mi función no invoca ninguna otra función, por lo que en ninguna parte de su recorrido debe desenmascarar un (pasar). ¿Qué puede causar sigprocmask falle?

¿Fue útil?

Solución

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).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top