1.\" $NetBSD: sigvec.3,v 1.11 1997/11/01 07:44:29 mycroft Exp $ 2.\" 3.\" Copyright (c) 1980, 1991 The Regents of the University of California. 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" from: @(#)sigvec.2 6.7 (Berkeley) 4/29/91 35.\" $NetBSD: sigvec.3,v 1.11 1997/11/01 07:44:29 mycroft Exp $ 36.\" 37.Dd November 1, 1997 38.Dt SIGVEC 3 39.Os BSD 4 40.Sh NAME 41.Nm sigvec 42.Nd software signal facilities 43.Sh SYNOPSIS 44.Fd #include <signal.h> 45.Bd -literal 46struct sigvec { 47 void (*sv_handler)(); 48 int sv_mask; 49 int sv_flags; 50}; 51.Ed 52.Ft int 53.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec" 54.Sh DESCRIPTION 55.Bf -symbolic 56This interface is made obsolete by 57.Xr sigaction 2 . 58.Ef 59.Pp 60The system defines a set of signals that may be delivered to a process. 61Signal delivery resembles the occurrence of a hardware interrupt: 62the signal is blocked from further occurrence, the current process 63context is saved, and a new one is built. A process may specify a 64.Em handler 65to which a signal is delivered, or specify that a signal is to be 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 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. The signal mask for a process is initialized 88from that of its parent (normally 0). It 89may be changed with a 90.Xr sigblock 3 91or 92.Xr sigsetmask 3 93call, or when a signal is delivered to the process. 94.Pp 95When a signal 96condition arises for a process, the signal is added to a set of 97signals pending for the process. If the signal is not currently 98.Em blocked 99by the process then it is delivered to the process. 100When a caught signal 101is delivered, the current state of the process is saved, 102a new signal mask is calculated (as described below), 103and the signal handler is invoked. The call to the handler 104is arranged so that if the signal handling routine returns 105normally the process will resume execution in the context 106from before the signal's delivery. 107If the process wishes to resume in a different context, then it 108must arrange to restore the previous context itself. 109.Pp 110When a signal is delivered to a process a new signal mask is 111installed for the duration of the process' signal handler 112(or until a 113.Xr sigblock 3 114or 115.Xr sigsetmask 3 116call is made). 117This mask is formed by taking the union of the current signal mask, 118the signal to be delivered, and 119the signal mask associated with the handler to be invoked. 120.Pp 121.Fn Sigvec 122assigns a handler for a specific signal. If 123.Fa vec 124is non-zero, it 125specifies an action 126.Pf ( Dv SIG_DFL , 127.Dv SIG_IGN , 128or a handler routine) and mask 129to be used when delivering the specified signal. 130Further, if the 131If 132.Fa ovec 133is non-zero, the previous handling information for the signal 134is returned to the user. 135.Pp 136Once a signal handler is installed, it remains installed 137until another 138.Fn sigvec 139call is made, or an 140.Xr execve 2 141is performed. 142A signal-specific default action may be reset by 143setting 144.Fa sv_handler 145to 146.Dv SIG_DFL . 147The defaults are process termination, possibly with core dump; 148no action; stopping the process; or continuing the process. 149See the signal list below for each signal's default action. 150If 151.Fa sv_handler 152is set to 153.Dv SIG_DFL , 154the default action for the signal is to discard the signal, 155and if a signal is pending, 156the pending signal is discarded even if the signal is masked. 157If 158.Fa sv_handler 159is set to 160.Dv SIG_IGN , 161current and pending instances 162of the signal are ignored and discarded. 163.Pp 164Options may be specified by setting 165.Em sv_flags . 166If the 167.Dv SV_ONSTACK 168bit is set in 169.Fa sv_flags , 170the system will deliver the signal to the process on a 171.Em "signal stack" , 172specified with 173.Xr sigstack 2 . 174.Pp 175If a signal is caught during the system calls listed below, 176the call may be restarted, 177the call may return with a data transfer shorter than requested, 178or the call may forced to terminate 179with the error 180.Dv EINTR . 181Interrupting of pending calls is requested 182by setting the 183.Dv SV_INTERRUPT 184bit in 185.Ar sv_flags . 186The affected system calls include 187.Xr open 2 , 188.Xr read 2 , 189.Xr write 2 , 190.Xr sendto 2 , 191.Xr recvfrom 2 , 192.Xr sendmsg 2 193and 194.Xr recvmsg 2 195on a communications channel or a slow device (such as a terminal, 196but not a regular file) 197and during a 198.Xr wait 2 199or 200.Xr ioctl 2 . 201However, calls that have already committed are not restarted, 202but instead return a partial success (for example, a short read count). 203.Pp 204After a 205.Xr fork 2 206or 207.Xr vfork 2 208all signals, the signal mask, the signal stack, 209and the interrupt/restart flags are inherited by the child. 210.Pp 211.Xr Execve 2 212reinstates the default 213action for all signals which were caught and 214resets all signals to be caught on the user stack. 215Ignored signals remain ignored; 216the signal mask remains the same; 217signals that interrupt pending system calls continue to do so. 218.Pp 219The following is a list of all signals 220with names as in the include file 221.Aq Pa signal.h : 222.Bl -column SIGVTALARMXX "create core imagexxx" 223.It Sy " NAME " " Default Action " " Description" 224.It Dv SIGHUP No " terminate process" " terminal line hangup" 225.It Dv SIGINT No " terminate process" " interrupt program" 226.It Dv SIGQUIT No " create core image" " quit program" 227.It Dv SIGILL No " create core image" " illegal instruction" 228.It Dv SIGTRAP No " create core image" " trace trap" 229.It Dv SIGABRT No " create core image" Xr abort 2 230call (formerly 231.Dv SIGIOT ) 232.It Dv SIGEMT No " create core image" " emulate instruction executed" 233.It Dv SIGFPE No " create core image" " floating-point exception" 234.It Dv SIGKILL No " terminate process" " kill program (cannot be caught or ignored)" 235.It Dv SIGBUS No " create core image" " bus error" 236.It Dv SIGSEGV No " create core image" " segmentation violation" 237.It Dv SIGSYS No " create core image" " system call given invalid argument" 238.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" 239.It Dv SIGALRM No " terminate process" " real-time timer expired" 240.It Dv SIGTERM No " terminate process" " software termination signal" 241.It Dv SIGURG No " discard signal" " urgent condition present on socket" 242.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" 243.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" 244.It Dv SIGCONT No " discard signal" " continue after stop" 245.It Dv SIGCHLD No " discard signal" " child status has changed" 246.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" 247.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" 248.It Dv SIGIO No " discard signal" Tn " I/O" 249is possible on a descriptor (see 250.Xr fcntl 2 ) 251.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" 252.Xr setrlimit 2 ) 253.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" 254.Xr setrlimit 2 ) 255.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" 256.Xr setitimer 2 ) 257.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" 258.Xr setitimer 2 ) 259.It Dv SIGWINCH No " discard signal" " window size change" 260.It Dv SIGINFO No " discard signal" " status request from keyboard" 261.It Dv SIGUSR1 No " terminate process" " user-defined signal 1" 262.It Dv SIGUSR2 No " terminate process" " 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. A \-1 return value 280indicates an error occurred and 281.Va errno 282is set to indicated the reason. 283.Sh EXAMPLE 284The handler routine can be declared: 285.Bd -literal -offset indent 286void 287handler(sig, code, scp) 288 int sig, code; 289 struct sigcontext *scp; 290.Ed 291.Pp 292Here 293.Fa sig 294is the signal number, into which the hardware faults and traps are 295mapped as defined below. 296.Fa Code 297is a parameter that is either a constant 298or the code provided by the hardware. 299.Fa Scp 300is a pointer to the 301.Fa sigcontext 302structure (defined in 303.Aq Pa signal.h ) , 304used to restore the context from before the signal. 305.Sh ERRORS 306.Fn Sigvec 307will fail and no new signal handler will be installed if one 308of the following occurs: 309.Bl -tag -width Er 310.It Bq Er EFAULT 311Either 312.Fa vec 313or 314.Fa ovec 315points to memory that is not a valid part of the process 316address space. 317.It Bq Er EINVAL 318.Fa Sig 319is not a valid signal number. 320.It Bq Er EINVAL 321An attempt is made to ignore or supply a handler for 322.Dv SIGKILL 323or 324.Dv SIGSTOP . 325.El 326.Sh SEE ALSO 327.Xr kill 1 , 328.Xr kill 2 , 329.Xr ptrace 2 , 330.Xr sigaction 2 , 331.Xr sigaltstack 2 , 332.Xr sigprocmask 2 , 333.Xr sigsuspend 2 , 334.Xr setjmp 3 , 335.Xr sigblock 3 , 336.Xr siginterrupt 3 , 337.Xr sigpause 3 , 338.Xr sigsetmask 3 , 339.Xr sigsetops 3 , 340.Xr sigstack 3 , 341.Xr tty 4 342