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