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