xref: /openbsd-src/lib/libc/compat-43/sigvec.3 (revision e324319b8a8a5b1105767b4beffb8d1ad9489904)
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.28 2011/09/03 22:59:07 jmc Exp $
29.\"
30.Dd $Mdocdate: September 3 2011 $
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 "SIGVTALRM" "create core image" "terminal line hangup"
226.It Sy "Name" Ta Sy "Default Action" Ta Sy "Description"
227.It Dv SIGHUP Ta "terminate process" Ta "terminal line hangup"
228.It Dv SIGINT Ta "terminate process" Ta "interrupt program"
229.It Dv SIGQUIT Ta "create core image" Ta "quit program"
230.It Dv SIGILL Ta "create core image" Ta "illegal instruction"
231.It Dv SIGTRAP Ta "create core image" Ta "trace trap"
232.It Dv SIGABRT Ta "create core image" Ta "abort(3) call (formerly SIGIOT)"
233.It Dv SIGEMT Ta "create core image" Ta "emulate instruction executed"
234.It Dv SIGFPE Ta "create core image" Ta "floating-point exception"
235.It Dv SIGKILL Ta "terminate process" Ta "kill program (cannot be caught or ignored)"
236.It Dv SIGBUS Ta "create core image" Ta "bus error"
237.It Dv SIGSEGV Ta "create core image" Ta "segmentation violation"
238.It Dv SIGSYS Ta "create core image" Ta "system call given invalid argument"
239.It Dv SIGPIPE Ta "terminate process" Ta "write on a pipe with no reader"
240.It Dv SIGALRM Ta "terminate process" Ta "real-time timer expired"
241.It Dv SIGTERM Ta "terminate process" Ta "software termination signal"
242.It Dv SIGURG Ta "discard signal" Ta "urgent condition present on socket"
243.It Dv SIGSTOP Ta "stop process" Ta "stop (cannot be caught or ignored)"
244.It Dv SIGTSTP Ta "stop process" Ta "stop signal generated from keyboard"
245.It Dv SIGCONT Ta "discard signal" Ta "continue after stop"
246.It Dv SIGCHLD Ta "discard signal" Ta "child status has changed"
247.It Dv SIGTTIN Ta "stop process" Ta "background read attempted from control terminal"
248.It Dv SIGTTOU Ta "stop process" Ta "background write attempted to control terminal"
249.It Dv SIGIO Ta "discard signal" Ta "I/O is possible on a descriptor (see"
250.Xr fcntl 2 )
251.It Dv SIGXCPU Ta "terminate process" Ta "CPU time limit exceeded (see"
252.Xr setrlimit 2 )
253.It Dv SIGXFSZ Ta "terminate process" Ta "file size limit exceeded (see"
254.Xr setrlimit 2 )
255.It Dv SIGVTALRM Ta "terminate process" Ta "virtual time alarm (see"
256.Xr setitimer 2 )
257.It Dv SIGPROF Ta "terminate process" Ta "profiling timer alarm (see"
258.Xr setitimer 2 )
259.It Dv SIGWINCH Ta "discard signal" Ta "window size change"
260.It Dv SIGINFO Ta "discard signal" Ta "status request from keyboard"
261.It Dv SIGUSR1 Ta "terminate process" Ta "user-defined signal 1"
262.It Dv SIGUSR2 Ta "terminate process" Ta "user-defined signal 2"
263.El
264.Sh NOTES
265The mask specified in
266.Fa vec
267is not allowed to block
268.Dv SIGKILL
269or
270.Dv SIGSTOP .
271This is enforced silently by the system.
272.Pp
273The
274.Dv SV_INTERRUPT
275flag is not available in
276.Bx 4.2 ,
277hence it should not be used if backward compatibility is needed.
278.Sh RETURN VALUES
279A 0 value indicated that the call succeeded.
280A \-1 return value indicates an error occurred and
281.Va errno
282is set to indicated the reason.
283.Sh EXAMPLES
284For an example of signal handler declarations, see
285.Xr sigaction 2 .
286.Sh ERRORS
287.Fn sigvec
288will fail and no new signal handler will be installed if one
289of the following occurs:
290.Bl -tag -width Er
291.It Bq Er EFAULT
292Either
293.Fa vec
294or
295.Fa ovec
296points to memory that is not a valid part of the process
297address space.
298.It Bq Er EINVAL
299.Fa sig
300is not a valid signal number.
301.It Bq Er EINVAL
302An attempt is made to ignore or supply a handler for
303.Dv SIGKILL
304or
305.Dv SIGSTOP .
306.El
307.Sh SEE ALSO
308.Xr kill 1 ,
309.Xr kill 2 ,
310.Xr ptrace 2 ,
311.Xr sigaction 2 ,
312.Xr sigaltstack 2 ,
313.Xr sigprocmask 2 ,
314.Xr sigstack 2 ,
315.Xr sigsuspend 2 ,
316.Xr setjmp 3 ,
317.Xr sigblock 3 ,
318.Xr siginterrupt 3 ,
319.Xr sigpause 3 ,
320.Xr sigsetmask 3 ,
321.Xr sigsetops 3 ,
322.Xr tty 4
323