xref: /freebsd/lib/libc/compat-43/sigvec.2 (revision 274b6244d3d8d81474b580ed282a83e99da41b62)
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 BSD 4
38.Sh NAME
39.Nm sigvec
40.Nd software signal facilities
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.Fd #include <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 sigaction(2).
57.Ef
58.Pp
59The system defines a set of signals that may be delivered to a process.
60Signal delivery resembles the occurrence of a hardware interrupt:
61the signal is blocked from further occurrence, the current process
62context is saved, and a new one is built.  A process may specify a
63.Em handler
64to which a signal is delivered, or specify that a signal is to be
65.Em blocked
66or
67.Em ignored .
68A process may also specify that a default action is to be taken
69by the system when a signal occurs.
70Normally, signal handlers execute on the current stack
71of the process.  This may be changed, on a per-handler basis,
72so that signals are taken on a special
73.Em "signal stack" .
74.Pp
75All signals have the same
76.Em priority .
77Signal routines execute with the signal that caused their
78invocation
79.Em blocked ,
80but other signals may yet occur.
81A global
82.Em "signal mask"
83defines the set of signals currently blocked from delivery
84to a process.  The signal mask for a process is initialized
85from that of its parent (normally 0).  It
86may be changed with a
87.Xr sigblock 2
88or
89.Xr sigsetmask 2
90call, or when a signal is delivered to the process.
91.Pp
92When a signal
93condition arises for a process, the signal is added to a set of
94signals pending for the process.  If the signal is not currently
95.Em blocked
96by the process then it is delivered to the process.  When a signal
97is delivered, the current state of the process is saved,
98a new signal mask is calculated (as described below),
99and the signal handler is invoked.  The call to the handler
100is arranged so that if the signal handling routine returns
101normally the process will resume execution in the context
102from before the signal's delivery.
103If the process wishes to resume in a different context, then it
104must arrange to restore the previous context itself.
105.Pp
106When a signal is delivered to a process a new signal mask is
107installed for the duration of the process' signal handler
108(or until a
109.Xr sigblock 2
110or
111.Xr sigsetmask 2
112call is made).
113This mask is formed by taking the current signal mask,
114adding the signal to be delivered, and
115.Em or Ns 'ing
116in the signal mask associated with the handler to be invoked.
117.Pp
118.Fn Sigvec
119assigns a handler for a specific signal.  If
120.Fa vec
121is non-zero, it
122specifies a handler routine and mask
123to be used when delivering the specified signal.
124Further, if the
125.Dv SV_ONSTACK
126bit is set in
127.Fa sv_flags ,
128the system will deliver the signal to the process on a
129.Em "signal stack" ,
130specified with
131.Xr sigaltstack 2 .
132If
133.Fa ovec
134is non-zero, the previous handling information for the signal
135is returned to the user.
136.Pp
137The following is a list of all signals
138with names as in the include file
139.Aq Pa signal.h :
140.Bl -column SIGVTALARMXX "create core imagexxx"
141.It Sy "  NAME  " "	  Default Action  " "	              Description"
142.It Dv SIGHUP No "	terminate process" "	terminal line hangup"
143.It Dv SIGINT No "	terminate process" "	interrupt program"
144.It Dv SIGQUIT No "	create core image" "	quit program"
145.It Dv SIGILL No "	create core image" "	illegal instruction"
146.It Dv SIGTRAP No "	create core image" "	trace trap"
147.It Dv SIGABRT No "	create core image" Xr 	abort 3
148call (formerly
149.Dv SIGIOT )
150.It Dv SIGEMT No "	create core image" "	emulate instruction executed"
151.It Dv SIGFPE No "	create core image" "	floating-point exception"
152.It Dv SIGKILL No "	terminate process" "	kill program"
153.It Dv SIGBUS No "	create core image" "	bus error"
154.It Dv SIGSEGV No "	create core image" "	segmentation violation"
155.It Dv SIGSYS No "	create core image" "	non-existent system call invoked"
156.It Dv SIGPIPE No "	terminate process" "	write on a pipe with no reader"
157.It Dv SIGALRM No "	terminate process" "	real-time timer expired"
158.It Dv SIGTERM No "	terminate process" "	software termination signal"
159.It Dv SIGURG No "	discard signal" "	urgent condition present on socket"
160.It Dv SIGSTOP No "	stop process" "	stop (cannot be caught or ignored)"
161.It Dv SIGTSTP No "	stop process" "	stop signal generated from keyboard"
162.It Dv SIGCONT No "	discard signal" "	continue after stop"
163.It Dv SIGCHLD No "	discard signal" "	child status has changed"
164.It Dv SIGTTIN No "	stop process" "	background read attempted from control terminal"
165.It Dv SIGTTOU No "	stop process" "	background write attempted to control terminal"
166.It Dv SIGIO No "	discard signal" Tn "	I/O"
167is possible on a descriptor (see
168.Xr fcntl 2 )
169.It Dv SIGXCPU No "	terminate process" "	cpu time limit exceeded (see"
170.Xr setrlimit 2 )
171.It Dv SIGXFSZ No "	terminate process" "	file size limit exceeded (see"
172.Xr setrlimit 2 )
173.It Dv SIGVTALRM No "	terminate process" "	virtual time alarm (see"
174.Xr setitimer 2 )
175.It Dv SIGPROF No "	terminate process" "	profiling timer alarm (see"
176.Xr setitimer 2 )
177.It Dv SIGWINCH No "	discard signal" "	Window size change"
178.It Dv SIGINFO No "	discard signal" "	status request from keyboard"
179.It Dv SIGUSR1 No "	terminate process" "	User defined signal 1"
180.It Dv SIGUSR2 No "	terminate process" "	User defined signal 2"
181.El
182.Pp
183Once a signal handler is installed, it remains installed
184until another
185.Fn sigvec
186call is made, or an
187.Xr execve 2
188is performed.
189A signal-specific default action may be reset by
190setting
191.Fa sv_handler
192to
193.Dv SIG_DFL .
194The defaults are process termination, possibly with core dump;
195no action; stopping the process; or continuing the process.
196See the above signal list for each signal's default action.
197If
198.Fa sv_handler
199is
200.Dv SIG_IGN
201current and pending instances
202of the signal are ignored and discarded.
203.Pp
204If a signal is caught during the system calls listed below,
205the call is normally restarted.
206The call can be forced to terminate prematurely with an
207.Dv EINTR
208error return by setting the
209.Dv SV_INTERRUPT
210bit in
211.Fa sv_flags .
212The affected system calls include
213.Xr read 2 ,
214.Xr write 2 ,
215.Xr sendto 2 ,
216.Xr recvfrom 2 ,
217.Xr sendmsg 2
218and
219.Xr recvmsg 2
220on a communications channel or a slow device (such as a terminal,
221but not a regular file)
222and during a
223.Xr wait 2
224or
225.Xr ioctl 2 .
226However, calls that have already committed are not restarted,
227but instead return a partial success (for example, a short read count).
228.Pp
229After a
230.Xr fork 2
231or
232.Xr vfork 2
233all signals, the signal mask, the signal stack,
234and the restart/interrupt flags are inherited by the child.
235.Pp
236.Xr Execve 2
237reinstates the default
238action for all signals which were caught and
239resets all signals to be caught on the user stack.
240Ignored signals remain ignored;
241the signal mask remains the same;
242signals that interrupt system calls continue to do so.
243.Sh NOTES
244The mask specified in
245.Fa vec
246is not allowed to block
247.Dv SIGKILL
248or
249.Dv SIGSTOP .
250This is done silently by the system.
251.Pp
252The
253.Dv SV_INTERRUPT
254flag is not available in
255.Bx 4.2 ,
256hence it should not be used if backward compatibility is needed.
257.Sh RETURN VALUES
258A 0 value indicated that the call succeeded.  A \-1 return value
259indicates an error occurred and
260.Va errno
261is set to indicated the reason.
262.Sh ERRORS
263.Fn Sigvec
264will fail and no new signal handler will be installed if one
265of the following occurs:
266.Bl -tag -width Er
267.It Bq Er EFAULT
268Either
269.Fa vec
270or
271.Fa ovec
272points to memory that is not a valid part of the process
273address space.
274.It Bq Er EINVAL
275.Fa Sig
276is not a valid signal number.
277.It Bq Er EINVAL
278An attempt is made to ignore or supply a handler for
279.Dv SIGKILL
280or
281.Dv SIGSTOP .
282.El
283.Sh SEE ALSO
284.Xr kill 1 ,
285.Xr kill 2 ,
286.Xr ptrace 2 ,
287.Xr sigaction 2 ,
288.Xr sigaltstack 2 ,
289.Xr sigblock 2 ,
290.Xr sigpause 2 ,
291.Xr sigprocmask 2 ,
292.Xr sigsetmask 2 ,
293.Xr sigsuspend 2 ,
294.Xr setjmp 3 ,
295.Xr siginterrupt 3 ,
296.Xr signal 3 ,
297.Xr sigsetops 3 ,
298.Xr tty 4
299.Sh EXAMPLE
300On the
301.Tn VAX\-11
302The handler routine can be declared:
303.Bd -literal -offset indent
304void handler(sig, code, scp)
305int sig, code;
306struct sigcontext *scp;
307.Ed
308.Pp
309Here
310.Fa sig
311is the signal number, into which the hardware faults and traps are
312mapped as defined below.
313.Fa Code
314is a parameter that is either a constant
315as given below or, for compatibility mode faults, the code provided by
316the hardware (Compatibility mode faults are distinguished from the
317other
318.Dv SIGILL
319traps by having
320.Dv PSL_CM
321set in the psl).
322.Fa Scp
323is a pointer to the
324.Fa sigcontext
325structure (defined in
326.Aq Pa signal.h ) ,
327used to restore the context from before the signal.
328.Sh BUGS
329This manual page is still confusing.
330