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