Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/ircsig.c
1069 views
1
/*
2
* ircsig.c: has a `my_signal()' that uses sigaction().
3
*
4
* written by matthew green, 1993.
5
*
6
* i stole bits of this from w. richard stevens' `advanced programming
7
* in the unix environment' -mrg
8
*/
9
10
11
#include "irc.h"
12
#include "irc_std.h"
13
14
sigfunc * my_signal(int sig_no, sigfunc *sig_handler, int misc_flags)
15
{
16
/*
17
* misc_flags is unused currently. it's planned to be used
18
* to use some of the doovier bits of sigaction(), if at
19
* some point we need them, -mrg
20
*/
21
22
struct sigaction sa = {{ 0 }}, osa = {{ 0 }};
23
24
if (sig_no < 0)
25
return NULL;
26
27
sa.sa_handler = sig_handler;
28
29
sigemptyset(&sa.sa_mask);
30
sigaddset(&sa.sa_mask, sig_no);
31
32
/* this is ugly, but the `correct' way. i hate c. -mrg */
33
sa.sa_flags = 0;
34
#if defined(SA_RESTART) || defined(SA_INTERRUPT)
35
if (SIGALRM == sig_no || SIGINT == sig_no)
36
{
37
# if defined(SA_INTERRUPT)
38
sa.sa_flags |= SA_INTERRUPT;
39
# endif /* SA_INTERRUPT */
40
}
41
else
42
{
43
# if defined(SA_RESTART)
44
sa.sa_flags |= SA_RESTART;
45
# endif /* SA_RESTART */
46
}
47
#endif /* SA_RESTART || SA_INTERRUPT */
48
49
if (0 > sigaction(sig_no, &sa, &osa))
50
return ((sigfunc *)SIG_ERR);
51
52
return ((sigfunc *)osa.sa_handler);
53
}
54
55