Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the sa_mask in sigset_t?

Tags:

c

gcc (GCC) 4.6.0 c89

I have a signal handler declared like this:

   /* Setup signal handler */
    struct sigaction new_action;
    new_action.sa_handler = g_signal_handler;
    new_action.sa_flags = SA_ONSTACK;

    if(sigaction(SIGINT, &new_action, NULL) == -1) {
        fprintf(stderr, "Failed to setup signal handlers.");
        return -1;
    }

When I was running my code through valgrind i.e. valgrind --leak-check=full it picked up the following error:

==5206== Syscall param rt_sigaction(act->sa_mask) points to uninitialised byte(s)
==5206==    at 0x347A435455: __libc_sigaction (in /lib64/libc-2.14.so)

So aftering looking at the man pages I decided to set like this, just to test with:

new_action.sa_mask = SA_NODEFER;

However, that just give me the following error:

error: incompatible types when assigning to type ‘__sigset_t’ from type ‘int’

Many thanks for any suggestions,

like image 236
ant2009 Avatar asked Aug 06 '11 06:08

ant2009


People also ask

What is Sa_mask?

sa_mask. A signal mask of type sigset_t that specifies an additional set of signals to be blocked during processing by the signal handling function specified by the sa_handler field. sa_flags. Flags that affect the behavior of the signal.

What sigemptyset() will do?

sigemptyset() is part of a family of functions that manipulate signal sets. Signal sets are data objects that let a process keep track of groups of signals. For example, a process can create one signal set to record which signals it is blocking, and another signal set to record which signals are pending.

What does sigaddset do in C?

The sigaddset() function adds the individual signal specified by the signo to the signal set pointed to by set. Applications shall call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object.

What is Sigaction in C?

DESCRIPTION. The sigaction() function allows the calling process to examine and/or specify the action to be associated with a specific signal. The argument sig specifies the signal; acceptable values are defined in <signal.


1 Answers

Try this:

/* Signals blocked during the execution of the handler. */
sigemptyset(&new_action.sa_mask);
sigaddset(&new_action.sa_mask, SIGINT);

The sa_mask field allows us to specify a set of signals that aren’t permitted to interrupt execution of this handler. In addition, the signal that caused the handler to be invoked is automatically added to the process signal mask.

like image 188
cnicutar Avatar answered Sep 30 '22 13:09

cnicutar