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