Portability of sigaction and sigset_t between Solaris and Linux

200 Views Asked by At

I have some legacy code on Solaris platform and I would like to port that to Linux, but I am getting some compilation error on Linux. On Solaris, I have the following code snippet:

#include <signal.h>
...
void f() {
    struct sigaction a;
    sigaction(sig,0,&a);
    std::cout << (void *) a.sa_handler
        << ", " << (void *) a.sa_sigaction
        << ", " << a.sa_mask.__sigbits[0]
        << ", " << a.sa_mask.__sigbits[1]
        << ", " << a.sa_mask.__sigbits[2]
        << ", " << a.sa_mask.__sigbits[3]
        << ", " << (void *) a.sa_flags
        << std::endl;
}

When I try to compile on Linux using gcc 4.9.2 (compiles ok on Solaris), I get the following compilation error:

error: struct __sigset_t has no member named __sigbits
     << ", " << a.sa_mask.__sigbits[0]

... and similarly for __sigbits[1], __sigbits[2], __sigbits[3] as well.

Is there any equivalent in Linux?

1

There are 1 best solutions below

0
dbush On

The POSIX compliant way to do this is to use the sigismember function.

int i;
for (i=0; i<32; i++) {
    printf("signal %d masked: %s\n", i, sigismember(&a.sa_mask, i) ? "yes", "no");
}