Signal handle with sigment

I need to process some signal using sigaction, but when I compile my code, I get this error:

warning: assignment from an incompatible pointer type

the code:

struct sigaction hup_act; ... hup_act.sa_flags=SA_SIGINFO; hup_act.sa_sigaction = sighupHandler; sigaction(SIGHUP, &hup_act, NULL); 

The warning refers to the purpose of hup_act.sa_sigaction. This warning causes a segmentation error when sending sighup to my application.

+6
source share
2 answers

If SA_SIGINFO set to struct sigaction member struct sigaction , use a method like

 void signalhandler(int, siginfo_t *, void *); 

as a handler function assigned by struct sigaction member sa_sigaction

else use a type method

 void signalhandler(int); 

as a handler function assigned by struct sigaction member sa_handler .

+6
source

Your sighupHandler should be one of two below:

 void sighupHandler(int) //for sa_handler 

or

 void sighupHandler(int, signinfo_t *, void *) //for sa_sigaction which is your case 

For more information about this, see here and here.

EDIT: Please refer to the links below and my links above for better clarity. I think that in your case, because of the common storage, as suggested below, the compiler generates only a warning, otherwise it would generate an error.

A 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 both sa_handler and sa_sigaction .

+5
source

Source: https://habr.com/ru/post/915569/


All Articles