c - What is the meaning of sigfillset? Do I really needed it in my implementation? -
i have next configuration:
static const signal_information signals_table [] = { // ignored signals. { sigtstp , true , sa_restart , null }, { sigquit , true , sa_restart , null }, { sigint , true , sa_restart , null }, { sigttou , true , sa_restart , null }, { sigttin , true , sa_restart , null }, { sighup , true , sa_restart , null }, // non-ignored signals. { sigterm , false , sa_restart , signal_term_handler }, { sigchld , false , sa_restart | sa_nocldstop , signal_child_handler } }; based on structure:
// signal info type definition. typedef struct { // signal identifier. int signal; // flag indicating if signal should ignored. bool ignore; // signal action flags used signal. int flags; // handler of signal. void (*handler) (void); } signal_information; and next function gets configuration , installs appropriate signals:
const bool setup_signals_support (void) { struct sigaction signal_action; memset (&signal_action, 0, sizeof (signal_action)); if (sigfillset (&signal_action.sa_mask) < 0) { log_error (failed_to_initialize_signal_set_message); homecoming false; } (int = 0; < (sizeof (signals_table) / sizeof (signals_table[0])); i++) { signal_action.sa_flags = signals_table[i].flags; signal_action.sa_handler = signals_table[i].ignore ? sig_ign : signal_dispatcher; if (sigaction (signals_table[i].signal, &signal_action, null) < 0) { log_error ("%s '%s'.", failed_to_change_signal_action_message, strsignal (signals_table[i].signal)); homecoming false; } } homecoming true; } question 1:
what want know if next fraction of code function necessary:
if (sigfillset (&signal_action.sa_mask) < 0) { log_error (failed_to_initialize_signal_set_message); homecoming false; } also, cannot understand meaning of sigfillset.
question 2:
can reuse same sigaction (signal_action) signals or have create new 1 each signal configuration record within function? want avoid sharing mutual configuration while installing signals. each signal configuration should not impact others. can reuse sigaction in such way?
thanks.
question 1
'sigfillset' initializes signal set contain signals. signal set sa_mask set of signals blocked when signal handler beingness executed. so, in case, when executing signal handler signals blocked , don't have worry signal interrupting signal handler. of course, on signals ignore sa_mask don't anything.
question 2
yes, can reuse struct (changing want change). scheme reads info needs , forgets in fact can destroy struct without problems (and happens when go out of scope, it's automatic variable).
c signals system handler
No comments:
Post a Comment