I need to handle some signal with sigaction, but when I compile my code I get this error:
warning: assignment from incompatible pointer type
the code is:
struct sigaction hup_act;
...
hup_act.sa_flags=SA_SIGINFO;
hup_act.sa_sigaction = sighupHandler;
sigaction(SIGHUP, &hup_act, NULL);
Warning is on hup_act.sa_sigaction assignment. This warning causes a segmentation fault when I send sighup to my application.
If SA_SIGINFO
is set in struct sigaction
's member sa_flags
use a method of type
void signalhandler(int, siginfo_t *, void *);
as handler function to be assigned to struct sigaction
's member sa_sigaction
else use a method of type
void signalhandler(int);
as handler function to be assigned to struct sigaction
's member sa_handler
.
Your sighupHandler must be one of the two below:
void sighupHandler(int) //for sa_handler
or
void sighupHandler(int, signinfo_t *, void *) //for sa_sigaction which is your case
For more info on this refer here and here
EDIT: Please refer to below and my above suggested links for better clarity. I think in your case because of common storage as suggested below, compiler is only generating a warning, else it would have generated an error.
The sigaction structure is defined as something like:
struct sigaction {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
};
On some architectures a union is involved: do not assign to both
sa_handler
andsa_sigaction
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With