Merge branch 'vendor/OPENSSH'
[dragonfly.git] / lib / libc / compat-43 / sigvec.3
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)sigvec.2    8.2 (Berkeley) 4/19/94
29 .\" $FreeBSD: src/lib/libc/compat-43/sigvec.2,v 1.9.2.8 2003/03/15 15:11:05 trhodes Exp $
30 .\"
31 .Dd November 26, 2016
32 .Dt SIGVEC 3
33 .Os
34 .Sh NAME
35 .Nm sigvec
36 .Nd software signal facilities
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In signal.h
41 .Bd -literal
42 struct sigvec {
43         void     (*sv_handler)();
44         int      sv_mask;
45         int      sv_flags;
46 };
47 .Ed
48 .Ft int
49 .Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec"
50 .Sh DESCRIPTION
51 .Bf -symbolic
52 This interface is made obsolete by
53 .Xr sigaction 2 .
54 .Ef
55 .Pp
56 The system defines a set of signals that may be delivered to a process.
57 Signal delivery resembles the occurrence of a hardware interrupt:
58 the signal is blocked from further occurrence, the current process
59 context is saved, and a new one is built.  A process may specify a
60 .Em handler
61 to which a signal is delivered, or specify that a signal is to be
62 .Em blocked
63 or
64 .Em ignored .
65 A process may also specify that a default action is to be taken
66 by the system when a signal occurs.
67 Normally, signal handlers execute on the current stack
68 of the process.  This may be changed, on a per-handler basis,
69 so that signals are taken on a special
70 .Em "signal stack" .
71 .Pp
72 All signals have the same
73 .Em priority .
74 Signal routines execute with the signal that caused their
75 invocation
76 .Em blocked ,
77 but other signals may yet occur.
78 A global
79 .Em "signal mask"
80 defines the set of signals currently blocked from delivery
81 to a process.  The signal mask for a process is initialized
82 from that of its parent (normally 0).  It
83 may be changed with a
84 .Xr sigblock 3
85 or
86 .Xr sigsetmask 3
87 call, or when a signal is delivered to the process.
88 .Pp
89 When a signal
90 condition arises for a process, the signal is added to a set of
91 signals pending for the process.  If the signal is not currently
92 .Em blocked
93 by the process then it is delivered to the process.  When a signal
94 is delivered, the current state of the process is saved,
95 a new signal mask is calculated (as described below),
96 and the signal handler is invoked.  The call to the handler
97 is arranged so that if the signal handling routine returns
98 normally the process will resume execution in the context
99 from before the signal's delivery.
100 If the process wishes to resume in a different context, then it
101 must arrange to restore the previous context itself.
102 .Pp
103 When a signal is delivered to a process a new signal mask is
104 installed for the duration of the process' signal handler
105 (or until a
106 .Xr sigblock 3
107 or
108 .Xr sigsetmask 3
109 call is made).
110 This mask is formed by taking the current signal mask,
111 adding the signal to be delivered, and
112 .Em or Ns 'ing
113 in the signal mask associated with the handler to be invoked.
114 .Pp
115 The
116 .Fn sigvec
117 function
118 assigns a handler for a specific signal.  If
119 .Fa vec
120 is non-zero, it
121 specifies a handler routine and mask
122 to be used when delivering the specified signal.
123 Further, if the
124 .Dv SV_ONSTACK
125 bit is set in
126 .Fa sv_flags ,
127 the system will deliver the signal to the process on a
128 .Em "signal stack" ,
129 specified with
130 .Xr sigaltstack 2 .
131 If
132 .Fa ovec
133 is non-zero, the previous handling information for the signal
134 is returned to the user.
135 .Pp
136 The following is a list of all signals
137 with names as in the include file
138 .In signal.h :
139 .Bl -column SIGVTALARMXX "create core imagexxx"
140 .It Sy "NAME    Default Action  Description"
141 .It Dv SIGHUP No "      terminate process" "    terminal line hangup"
142 .It Dv SIGINT No "      terminate process" "    interrupt program"
143 .It Dv SIGQUIT No "     create core image" "    quit program"
144 .It Dv SIGILL No "      create core image" "    illegal instruction"
145 .It Dv SIGTRAP No "     create core image" "    trace trap"
146 .It Dv SIGABRT No "     create core image" Ta Xr abort 3
147 call (formerly
148 .Dv SIGIOT )
149 .It Dv SIGEMT No "      create core image" "    emulate instruction executed"
150 .It Dv SIGFPE No "      create core image" "    floating-point exception"
151 .It Dv SIGKILL No "     terminate process" "    kill program"
152 .It Dv SIGBUS No "      create core image" "    bus error"
153 .It Dv SIGSEGV No "     create core image" "    segmentation violation"
154 .It Dv SIGSYS No "      create core image" "    non-existent system call invoked"
155 .It Dv SIGPIPE No "     terminate process" "    write on a pipe with no reader"
156 .It Dv SIGALRM No "     terminate process" "    real-time timer expired"
157 .It Dv SIGTERM No "     terminate process" "    software termination signal"
158 .It Dv SIGURG No "      discard signal" "       urgent condition present on socket"
159 .It Dv SIGSTOP No "     stop process" " stop (cannot be caught or ignored)"
160 .It Dv SIGTSTP No "     stop process" " stop signal generated from keyboard"
161 .It Dv SIGCONT No "     discard signal" "       continue after stop"
162 .It Dv SIGCHLD No "     discard signal" "       child status has changed"
163 .It Dv SIGTTIN No "     stop process" " background read attempted from control terminal"
164 .It Dv SIGTTOU No "     stop process" " background write attempted to control terminal"
165 .It Dv SIGIO No "       discard signal" Tn "    I/O"
166 is possible on a descriptor (see
167 .Xr fcntl 2 )
168 .It Dv SIGXCPU No "     terminate process" "    cpu time limit exceeded (see"
169 .Xr setrlimit 2 )
170 .It Dv SIGXFSZ No "     terminate process" "    file size limit exceeded (see"
171 .Xr setrlimit 2 )
172 .It Dv SIGVTALRM No "   terminate process" "    virtual time alarm (see"
173 .Xr setitimer 2 )
174 .It Dv SIGPROF No "     terminate process" "    profiling timer alarm (see"
175 .Xr setitimer 2 )
176 .It Dv SIGWINCH No "    discard signal" "       Window size change"
177 .It Dv SIGINFO No "     discard signal" "       status request from keyboard"
178 .It Dv SIGUSR1 No "     terminate process" "    User defined signal 1"
179 .It Dv SIGUSR2 No "     terminate process" "    User defined signal 2"
180 .El
181 .Pp
182 Once a signal handler is installed, it remains installed
183 until another
184 .Fn sigvec
185 call is made, or an
186 .Xr execve 2
187 is performed.
188 A signal-specific default action may be reset by
189 setting
190 .Fa sv_handler
191 to
192 .Dv SIG_DFL .
193 The defaults are process termination, possibly with core dump;
194 no action; stopping the process; or continuing the process.
195 See the above signal list for each signal's default action.
196 If
197 .Fa sv_handler
198 is
199 .Dv SIG_IGN
200 current and pending instances
201 of the signal are ignored and discarded.
202 .Pp
203 If a signal is caught during the system calls listed below,
204 the call is normally restarted.
205 The call can be forced to terminate prematurely with an
206 .Er EINTR
207 error return by setting the
208 .Dv SV_INTERRUPT
209 bit in
210 .Fa sv_flags .
211 The affected system calls include
212 .Xr read 2 ,
213 .Xr write 2 ,
214 .Xr sendto 2 ,
215 .Xr recvfrom 2 ,
216 .Xr sendmsg 2
217 and
218 .Xr recvmsg 2
219 on a communications channel or a slow device (such as a terminal,
220 but not a regular file)
221 and during a
222 .Xr wait 2
223 or
224 .Xr ioctl 2 .
225 However, calls that have already committed are not restarted,
226 but instead return a partial success (for example, a short read count).
227 .Pp
228 After a
229 .Xr fork 2
230 or
231 .Xr vfork 2
232 all signals, the signal mask, the signal stack,
233 and the restart/interrupt flags are inherited by the child.
234 .Pp
235 The
236 .Xr execve 2
237 system call reinstates the default
238 action for all signals which were caught and
239 resets all signals to be caught on the user stack.
240 Ignored signals remain ignored;
241 the signal mask remains the same;
242 signals that interrupt system calls continue to do so.
243 .Sh NOTES
244 The mask specified in
245 .Fa vec
246 is not allowed to block
247 .Dv SIGKILL
248 or
249 .Dv SIGSTOP .
250 This is done silently by the system.
251 .Pp
252 The
253 .Dv SV_INTERRUPT
254 flag is not available in
255 .Bx 4.2 ,
256 hence it should not be used if backward compatibility is needed.
257 .Sh RETURN VALUES
258 .Rv -std sigvec
259 .Sh EXAMPLES
260 On the
261 .Tn VAX\-11
262 The handler routine can be declared:
263 .Bd -literal -offset indent
264 void handler(sig, code, scp)
265 int sig, code;
266 struct sigcontext *scp;
267 .Ed
268 .Pp
269 Here
270 .Fa sig
271 is the signal number, into which the hardware faults and traps are
272 mapped as defined below.
273 The
274 .Fa code
275 argument
276 is either a constant
277 as given below or, for compatibility mode faults, the code provided by
278 the hardware (Compatibility mode faults are distinguished from the
279 other
280 .Dv SIGILL
281 traps by having
282 .Dv PSL_CM
283 set in the psl).
284 The
285 .Fa scp
286 argument
287 is a pointer to the
288 .Fa sigcontext
289 structure (defined in
290 .In signal.h ) ,
291 used to restore the context from before the signal.
292 .Sh ERRORS
293 The
294 .Fn sigvec
295 function
296 will fail and no new signal handler will be installed if one
297 of the following occurs:
298 .Bl -tag -width Er
299 .It Bq Er EFAULT
300 Either
301 .Fa vec
302 or
303 .Fa ovec
304 points to memory that is not a valid part of the process
305 address space.
306 .It Bq Er EINVAL
307 The
308 .Fa sig
309 argument
310 is not a valid signal number.
311 .It Bq Er EINVAL
312 An attempt is made to ignore or supply a handler for
313 .Dv SIGKILL
314 or
315 .Dv SIGSTOP .
316 .El
317 .Sh SEE ALSO
318 .Xr kill 1 ,
319 .Xr kill 2 ,
320 .Xr ptrace 2 ,
321 .Xr sigaction 2 ,
322 .Xr sigaltstack 2 ,
323 .Xr sigprocmask 2 ,
324 .Xr sigsuspend 2 ,
325 .Xr setjmp 3 ,
326 .Xr sigblock 3 ,
327 .Xr siginterrupt 3 ,
328 .Xr signal 3 ,
329 .Xr sigpause 3 ,
330 .Xr sigsetmask 3 ,
331 .Xr sigsetops 3 ,
332 .Xr tty 4
333 .Sh BUGS
334 This manual page is still confusing.