aboutsummaryrefslogtreecommitdiff
path: root/share/man/man9/signal.9
blob: 6f377eeb346bf39740ba05f7c2b0fc67dd4b32f2 (plain) (blame)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
.\"
.\" Copyright (C) 2002 Chad David <davidc@FreeBSD.org>. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice(s), this list of conditions and the following disclaimer as
.\"    the first lines of this file unmodified other than the possible
.\"    addition of one or more copyright notices.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice(s), this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
.\" DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd November 20, 2004
.Dt SIGNAL 9
.Os
.Sh NAME
.Nm signal ,
.Nm SIGADDSET ,
.Nm SIGDELSET ,
.Nm SETEMPTYSET ,
.Nm SIGFILLSET ,
.Nm SIGISMEMBER ,
.Nm SIGISEMPTY ,
.Nm SIGNOTEMPTY ,
.Nm SIGSETEQ ,
.Nm SIGSETNEQ ,
.Nm SIGSETOR ,
.Nm SIGSETAND ,
.Nm SIGSETNAND ,
.Nm SIGSETCANTMASK ,
.Nm SIG_STOPSIGMASK ,
.Nm SIG_CONTSIGMASK ,
.Nm SIGPENDING ,
.Nm cursig ,
.Nm execsigs ,
.Nm issignal ,
.Nm killproc ,
.Nm pgsigio ,
.Nm postsig ,
.Nm sigexit ,
.Nm siginit ,
.Nm signotify ,
.Nm trapsignal
.Nd "kernel signal functions"
.Sh SYNOPSIS
.In sys/param.h
.In sys/proc.h
.In sys/signalvar.h
.Ft void
.Fn SIGADDSET "sigset_t set" "int signo"
.Ft void
.Fn SIGDELSET "sigset_t set" "int signo"
.Ft void
.Fn SIGEMPTYSET "sigset_t set"
.Ft void
.Fn SIGFILLSET "sigset_t set"
.Ft int
.Fn SIGISMEMBER "sigset_t set" "int signo"
.Ft int
.Fn SIGISEMPTY "sigset_t set"
.Ft int
.Fn SIGNOTEMPTY "sigset_t set"
.Ft int
.Fn SIGSETEQ "sigset_t set1" "sigset_t set2"
.Ft int
.Fn SIGSETNEQ "sigset_t set1" "sigset_t set2"
.Ft void
.Fn SIGSETOR "sigset_t set1" "sigset_t set2"
.Ft void
.Fn SIGSETAND "sigset_t set1" "sigset_t set2"
.Ft void
.Fn SIGSETNAND "sigset_t set1" "sigset_t set2"
.Ft void
.Fn SIG_CANTMASK "sigset_t set"
.Ft void
.Fn SIG_STOPSIGMASK "sigset_t set"
.Ft void
.Fn SIG_CONTSIGMASK "sigset_t set"
.Ft int
.Fn SIGPENDING "struct proc *p"
.Ft int
.Fn cursig "struct thread *td"
.Ft void
.Fn execsigs "struct proc *p"
.Ft int
.Fn issignal "struct thread *td"
.Ft void
.Fn killproc "struct proc *p" "char *why"
.Ft void
.Fn pgsigio "struct sigio **sigiop" "int sig" "int checkctty"
.Ft void
.Fn postsig "int sig"
.Ft void
.Fn sigexit "struct thread *td" "int signum"
.Ft void
.Fn siginit "struct proc *p"
.Ft void
.Fn signotify "struct thread *td"
.Ft void
.Fn trapsignal "struct thread *td" "int sig" "u_long code"
.Sh DESCRIPTION
The
.Fn SIGADDSET
macro adds
.Fa signo
to
.Fa set .
No effort is made to ensure that
.Fa signo
is a valid signal number.
.Pp
The
.Fn SIGDELSET
macro removes
.Fa signo
from
.Fa set .
No effort is made to ensure that
.Fa signo
is a valid signal number.
.Pp
The
.Fn SIGEMPTYSET
macro clears all signals in
.Fa set .
.Pp
The
.Fn SIGFILLSET
macro sets all signals in
.Fa set .
.Pp
The
.Fn SIGISMEMBER
macro determines if
.Fa signo
is set in
.Fa set .
.Pp
The
.Fn SIGISEMPTY
macro determines if
.Fa set
does not have any signals set.
.Pp
The
.Fn SIGNOTEMPTY
macro determines if
.Fa set
has any signals set.
.Pp
The
.Fn SIGSETEQ
macro determines if two signal sets are equal; that is, the same signals
are set in both.
.Pp
The
.Fn SIGSETNEQ
macro determines if two signal sets differ; that is, if any signal set in
one is not set in the other.
.Pp
The
.Fn SIGSETOR
macro ORs the signals set in
.Fa set2
into
.Fa set1 .
.Pp
The
.Fn SIGSETAND
macro ANDs the signals set in
.Fa set2
into
.Fa set1 .
.Pp
The
.Fn SIGSETNAND
macro NANDs the signals set in
.Fa set2
into
.Fa set1 .
.Pp
The
.Fn SIG_CANTMASK
macro clears the
.Dv SIGKILL
and
.Dv SIGSTOP
signals from
.Fa set .
These two signals cannot be blocked or caught and
.Fn SIG_CANTMASK
is used in code where signals are manipulated to ensure this policy
is enforced.
.Pp
The
.Fn SIG_STOPSIGMASK
macro clears the
.Dv SIGSTOP ,
.Dv SIGTSTP ,
.Dv SIGTTIN ,
and
.Dv SIGTTOU
signals from
.Fa set .
.Fn SIG_STOPSIGMASK
is used to clear stop signals when a process is waiting for a child to
exit or exec, and when a process is continuing after having been
suspended.
.Pp
The
.Fn SIG_CONTSIGMASK
macro clears the
.Dv SIGCONT
signal from
.Fa set .
.Fn SIG_CONTSIGMASK
is called when a process is stopped.
.Pp
The
.Fn SIGPENDING
macro determines if the given process has any pending signals that are
not masked.
If the process has a pending signal and the process is currently being
traced,
.Fn SIGPENDING
will return true even if the signal is masked.
.Pp
The
.Fn cursig
function returns the signal number that should be delivered to process
.Fa td->td_proc .
If there are no signals pending, zero is returned.
.Pp
The
.Fn execsigs
function resets the signal set and signal stack of a process in preparation
for an
.Xr execve 2 .
The lock for
.Fa p
must be held before
.Fn execsigs
is called.
.Pp
The
.Fn issignal
function determines if there are any pending signals for process
.Fa td->td_proc
that should be caught, or cause this process to terminate or interrupt its
current system call.
If process
.Fa td->td_proc
is currently being traced, ignored signals will be handled and the process
is always stopped.
Stop signals are handled and cleared right away by
.Fn issignal
unless the process is a member of an orphaned process group and the stop
signal originated from a TTY.
The
.Va sched_lock
lock may be acquired and released, and if
.Va Giant
is held, it may be released and reacquired.
The
.Vt sigacts
structure
.Fa td->td_proc->p_sigacts
must be locked before calling
.Fn issignal
and may be released and reacquired during the call.
The process lock for
.Fa td->td_proc
must be acquired before calling
.Fn issignal
and may be released and reacquired during the call.
The lock for the parent of
.Fa td->td_proc
may also be acquired and released.
Default signal actions are not taken for system processes and init.
.Pp
The
.Fn killproc
function delivers
.Dv SIGKILL
to
.Fa p .
.Fa why
is logged as the reason
.Em why
the process was killed.
.Pp
The
.Fn pgsigio
function sends the signal
.Fa sig
to the process or process group
.Fa sigiop->sio_pgid .
If
.Fa checkctty
is non-zero, the signal is only delivered to processes in the process group
that have a controlling terminal.
If
.Fa sigiop->sio_pgid
is for a process (> 0), the lock for
.Fa sigiop->sio_proc
is acquired and released.
If
.Fa sigiop->sio_pgid
is for a process group (< 0), the process group lock for
.Fa sigiop->sio_pgrp
is acquired and released.
The lock
.Va sigio_lock
is acquired and released.
.Pp
The
.Fn postsig
function handles the actual delivery of the signal
.Fa sig .
.Fn postsig
is called from
.Fn ast
after the kernel has been notified that a signal should be delivered
(via a call to
.Fn signotify ,
which causes the flag
.Dv PS_NEEDSIGCHK
to be set).
The lock for process that owns
.Va curthread
must be held before
.Fn postsig
is called, and the current process cannot be 0.
The lock for the
.Va p_sigacts
field of the current process must be held before
.Fn postsig
is called, and may be released and reacquired.
.Pp
The
.Fn sigexit
function causes the process that owns
.Fa td
to exit with a return value of signal number
.Fa sig .
If required, the process will dump core.
The lock for the process that owns
.Fa td
must be held before
.Fn sigexit
is called.
.Pp
The
.Fn siginit
function is called during system initialization to cause every signal with
a default property of
.Dv SA_IGNORE
(except
.Dv SIGCONT )
to be ignored by
.Fa p .
The process lock for
.Fa p
is acquired and released by
.Fn siginit .
The only process that
.Fn siginit
is ever called for
is
.Va proc0 .
.Pp
The
.Fn signotify
function flags that there are unmasked signals pending that
.Fn ast
should handle.
The lock for process
.Fa td->td_proc
must be held before
.Fn signotify
is called, and
.Va sched_lock
is acquired and released.
.Pp
The
.Fn trapsignal
function sends a signal that is the result of a trap to process
.Fa td->td_proc .
If the process is not being traced and the signal can be delivered
immediately,
.Fn trapsignal
will deliver it directly; otherwise,
.Fn trapsignal
will call
.Xr psignal 9
to cause the signal to be delivered.
The
.Va sched_lock
lock is acquired and released, as is the lock for
.Fa td->td_proc .
The lock for the
.Va p_sigacts
field of
.Fa td->td_proc
is acquired and released.
.Sh RETURN VALUES
The
.Fn SIGISMEMBER ,
.Fn SIGISEMPTY ,
.Fn SIGNOTEMPTY ,
.Fn SIGSETEQ ,
.Fn SIGSETNEQ ,
and
.Fn SIGPENDING
macros all return non-zero (true) if the condition they are checking
is found to be true; otherwise, zero (false) is returned.
.Pp
The
.Fn cursig
function returns either a valid signal number or zero.
.Pp
.Fn issignal
returns either a valid signal number or zero.
.Sh SEE ALSO
.Xr gsignal 9 ,
.Xr pgsignal 9 ,
.Xr psignal 9
.Sh AUTHORS
This manual page was written by
.An Chad David Aq davidc@FreeBSD.org .