/*1* ircsig.c: has a `my_signal()' that uses sigaction().2*3* written by matthew green, 1993.4*5* i stole bits of this from w. richard stevens' `advanced programming6* in the unix environment' -mrg7*/8910#include "irc.h"11#include "irc_std.h"1213sigfunc * my_signal(int sig_no, sigfunc *sig_handler, int misc_flags)14{15/*16* misc_flags is unused currently. it's planned to be used17* to use some of the doovier bits of sigaction(), if at18* some point we need them, -mrg19*/2021struct sigaction sa = {{ 0 }}, osa = {{ 0 }};2223if (sig_no < 0)24return NULL;2526sa.sa_handler = sig_handler;2728sigemptyset(&sa.sa_mask);29sigaddset(&sa.sa_mask, sig_no);3031/* this is ugly, but the `correct' way. i hate c. -mrg */32sa.sa_flags = 0;33#if defined(SA_RESTART) || defined(SA_INTERRUPT)34if (SIGALRM == sig_no || SIGINT == sig_no)35{36# if defined(SA_INTERRUPT)37sa.sa_flags |= SA_INTERRUPT;38# endif /* SA_INTERRUPT */39}40else41{42# if defined(SA_RESTART)43sa.sa_flags |= SA_RESTART;44# endif /* SA_RESTART */45}46#endif /* SA_RESTART || SA_INTERRUPT */4748if (0 > sigaction(sig_no, &sa, &osa))49return ((sigfunc *)SIG_ERR);5051return ((sigfunc *)osa.sa_handler);52}535455