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