summaryrefslogtreecommitdiff
path: root/src/sig.c
blob: 4b81e1b5c65d823eef1bb9c80b5e8a95b2ac2278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "sig.h"

#include <signal.h>

/**
  @file sig.c
  @authors djb, jmh
  @ref qmail
  @brief signal handling functions
*/

void sig_alarmblock()
{
  sig_block(SIGALRM);
}

void sig_alarmunblock()
{
  sig_unblock(SIGALRM);
}

void sig_alarmcatch(void (*f)(void))
{
  sig_catch(SIGALRM, (void (*)(int))f);
}

void sig_alarmdefault()
{
  sig_catch(SIGALRM, SIG_DFL);
}

int sig_alarm = SIGALRM;

void sig_block(int sig)
{
  sigset_t ss;
  sigemptyset(&ss);
  sigaddset(&ss, sig);
  sigprocmask(SIG_BLOCK, &ss, (sigset_t *)0);
}

void sig_unblock(int sig)
{
  sigset_t ss;
  sigemptyset(&ss);
  sigaddset(&ss, sig);
  sigprocmask(SIG_UNBLOCK, &ss, (sigset_t *)0);
}

void sig_blocknone()
{
  sigset_t ss;
  sigemptyset(&ss);
  sigprocmask(SIG_SETMASK, &ss, (sigset_t *)0);
}

void sig_catch(int sig, void (*f)(int))
{
  struct sigaction sa;
  sa.sa_handler = f;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  sigaction(sig, &sa, (struct sigaction *)0);
}

void sig_pause()
{
  sigset_t ss;
  sigemptyset(&ss);
  sigsuspend(&ss);
}

void sig_pipeignore()
{
  sig_catch(SIGPIPE, SIG_IGN);
}

void sig_pipedefault()
{
  sig_catch(SIGPIPE, SIG_DFL);
}

int sig_pipe = SIGPIPE;

void sig_childblock()
{
  sig_block(SIGCHLD);
}

void sig_childunblock()
{
  sig_unblock(SIGCHLD);
}

void sig_childcatch(void (*f)(void))
{
  sig_catch(SIGCHLD, (void (*)(int))f);
}

void sig_childdefault()
{
  sig_catch(SIGCHLD, SIG_DFL);
}

int sig_child = SIGCHLD;

void sig_hangupblock()
{
  sig_block(SIGHUP);
}

void sig_hangupunblock()
{
  sig_unblock(SIGHUP);
}

void sig_hangupcatch(void (*f)(void))
{
  sig_catch(SIGHUP, (void (*)(int))f);
}

void sig_hangupdefault()
{
  sig_catch(SIGHUP, SIG_DFL);
}

int sig_hangup = SIGHUP;

void sig_termblock()
{
  sig_block(SIGTERM);
}

void sig_termunblock()
{
  sig_unblock(SIGTERM);
}

void sig_termcatch(void (*f)(void))
{
  sig_catch(SIGTERM, (void (*)(int))f);
}

void sig_termdefault()
{
  sig_catch(SIGTERM, SIG_DFL);
}

int sig_term = SIGTERM;

void sig_bugcatch(void (*f)(int))
{
  sig_catch(SIGILL, f);
  sig_catch(SIGABRT, f);
  sig_catch(SIGFPE, f);
  sig_catch(SIGBUS, f);
  sig_catch(SIGSEGV, f);
#ifdef SIGSYS
  sig_catch(SIGSYS, f);
#endif
#ifdef SIGEMT
  sig_catch(SIGEMT, f);
#endif
}

void (*sig_defaulthandler)(int) = SIG_DFL;

void sig_miscignore()
{
  sig_catch(SIGVTALRM, SIG_IGN);
  sig_catch(SIGPROF, SIG_IGN);
  sig_catch(SIGQUIT, SIG_IGN);
  sig_catch(SIGINT, SIG_IGN);
  sig_catch(SIGHUP, SIG_IGN);
#ifdef SIGXCPU
  sig_catch(SIGXCPU, SIG_IGN);
#endif
#ifdef SIGXFSZ
  sig_catch(SIGXFSZ, SIG_IGN);
#endif
}

void (*sig_ignorehandler)(int) = SIG_IGN;

int sig_cont = SIGCONT;