1*2fe8fb19SBen Gras.\" $NetBSD: sigvec.3,v 1.26 2010/03/22 19:30:53 joerg Exp $ 2*2fe8fb19SBen Gras.\" 3*2fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993 4*2fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 5*2fe8fb19SBen Gras.\" 6*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 7*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 8*2fe8fb19SBen Gras.\" are met: 9*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 10*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 11*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 12*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 13*2fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 14*2fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 15*2fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 16*2fe8fb19SBen Gras.\" without specific prior written permission. 17*2fe8fb19SBen Gras.\" 18*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*2fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*2fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22*2fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*2fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*2fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*2fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*2fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*2fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*2fe8fb19SBen Gras.\" SUCH DAMAGE. 29*2fe8fb19SBen Gras.\" 30*2fe8fb19SBen Gras.\" from: @(#)sigvec.2 8.2 (Berkeley) 4/19/94 31*2fe8fb19SBen Gras.\" 32*2fe8fb19SBen Gras.Dd December 3, 2005 33*2fe8fb19SBen Gras.Dt SIGVEC 3 34*2fe8fb19SBen Gras.Os 35*2fe8fb19SBen Gras.Sh NAME 36*2fe8fb19SBen Gras.Nm sigvec 37*2fe8fb19SBen Gras.Nd software signal facilities 38*2fe8fb19SBen Gras.Sh LIBRARY 39*2fe8fb19SBen Gras.Lb libc 40*2fe8fb19SBen Gras.Sh SYNOPSIS 41*2fe8fb19SBen Gras.In signal.h 42*2fe8fb19SBen Gras.Bd -literal 43*2fe8fb19SBen Grasstruct sigvec { 44*2fe8fb19SBen Gras void (*sv_handler)(); 45*2fe8fb19SBen Gras int sv_mask; 46*2fe8fb19SBen Gras int sv_flags; 47*2fe8fb19SBen Gras}; 48*2fe8fb19SBen Gras.Ed 49*2fe8fb19SBen Gras.Ft int 50*2fe8fb19SBen Gras.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec" 51*2fe8fb19SBen Gras.Sh DESCRIPTION 52*2fe8fb19SBen Gras.Bf -symbolic 53*2fe8fb19SBen GrasThis interface is made obsolete by 54*2fe8fb19SBen Gras.Xr sigaction 2 . 55*2fe8fb19SBen GrasThe structure, flags, and function declaration have been removed from 56*2fe8fb19SBen Grasthe header files but the function is kept in the c library for binary 57*2fe8fb19SBen Grascompatibility. 58*2fe8fb19SBen Gras.Ef 59*2fe8fb19SBen Gras.Pp 60*2fe8fb19SBen GrasThe system defines a set of signals that may be delivered to a process. 61*2fe8fb19SBen GrasSignal delivery resembles the occurrence of a hardware interrupt: 62*2fe8fb19SBen Grasthe signal is blocked from further occurrence, the current process 63*2fe8fb19SBen Grascontext is saved, and a new one is built. 64*2fe8fb19SBen GrasA process may specify a 65*2fe8fb19SBen Gras.Em handler 66*2fe8fb19SBen Grasto which a signal is delivered, or specify that a signal is to be 67*2fe8fb19SBen Gras.Em ignored . 68*2fe8fb19SBen GrasA process may also specify that a default action is to be taken 69*2fe8fb19SBen Grasby the system when a signal occurs. 70*2fe8fb19SBen GrasA signal may also be 71*2fe8fb19SBen Gras.Em blocked , 72*2fe8fb19SBen Grasin which case its delivery is postponed until it is 73*2fe8fb19SBen Gras.Em unblocked . 74*2fe8fb19SBen GrasThe action to be taken on delivery is determined at the time 75*2fe8fb19SBen Grasof delivery. 76*2fe8fb19SBen GrasNormally, signal handlers execute on the current stack 77*2fe8fb19SBen Grasof the process. 78*2fe8fb19SBen GrasThis may be changed, on a per-handler basis, so that signals are 79*2fe8fb19SBen Grastaken on a special 80*2fe8fb19SBen Gras.Em "signal stack" . 81*2fe8fb19SBen Gras.Pp 82*2fe8fb19SBen GrasSignal routines execute with the signal that caused their 83*2fe8fb19SBen Grasinvocation 84*2fe8fb19SBen Gras.Em blocked , 85*2fe8fb19SBen Grasbut other signals may yet occur. 86*2fe8fb19SBen GrasA global 87*2fe8fb19SBen Gras.Em "signal mask" 88*2fe8fb19SBen Grasdefines the set of signals currently blocked from delivery 89*2fe8fb19SBen Grasto a process. 90*2fe8fb19SBen GrasThe signal mask for a process is initialized from that of its parent 91*2fe8fb19SBen Gras(normally 0). 92*2fe8fb19SBen GrasIt may be changed with a 93*2fe8fb19SBen Gras.Xr sigblock 3 94*2fe8fb19SBen Grasor 95*2fe8fb19SBen Gras.Xr sigsetmask 3 96*2fe8fb19SBen Grascall, or when a signal is delivered to the process. 97*2fe8fb19SBen Gras.Pp 98*2fe8fb19SBen GrasWhen a signal 99*2fe8fb19SBen Grascondition arises for a process, the signal is added to a set of 100*2fe8fb19SBen Grassignals pending for the process. 101*2fe8fb19SBen GrasIf the signal is not currently 102*2fe8fb19SBen Gras.Em blocked 103*2fe8fb19SBen Grasby the process then it is delivered to the process. 104*2fe8fb19SBen GrasWhen a caught signal 105*2fe8fb19SBen Grasis delivered, the current state of the process is saved, 106*2fe8fb19SBen Grasa new signal mask is calculated (as described below), 107*2fe8fb19SBen Grasand the signal handler is invoked. 108*2fe8fb19SBen GrasThe call to the handler is arranged so that if the signal handling 109*2fe8fb19SBen Grasroutine returns normally the process will resume execution in the 110*2fe8fb19SBen Grascontext from before the signal's delivery. 111*2fe8fb19SBen GrasIf the process wishes to resume in a different context, then it 112*2fe8fb19SBen Grasmust arrange to restore the previous context itself. 113*2fe8fb19SBen Gras.Pp 114*2fe8fb19SBen GrasWhen a signal is delivered to a process a new signal mask is 115*2fe8fb19SBen Grasinstalled for the duration of the process' signal handler 116*2fe8fb19SBen Gras(or until a 117*2fe8fb19SBen Gras.Xr sigblock 3 118*2fe8fb19SBen Grasor 119*2fe8fb19SBen Gras.Xr sigsetmask 3 120*2fe8fb19SBen Grascall is made). 121*2fe8fb19SBen GrasThis mask is formed by taking the union of the current signal mask, 122*2fe8fb19SBen Grasthe signal to be delivered, and 123*2fe8fb19SBen Grasthe signal mask associated with the handler to be invoked. 124*2fe8fb19SBen Gras.Pp 125*2fe8fb19SBen Gras.Fn sigvec 126*2fe8fb19SBen Grasassigns a handler for a specific signal. 127*2fe8fb19SBen GrasIf 128*2fe8fb19SBen Gras.Fa vec 129*2fe8fb19SBen Grasis non-zero, it 130*2fe8fb19SBen Grasspecifies an action 131*2fe8fb19SBen Gras.Pf ( Dv SIG_DFL , 132*2fe8fb19SBen Gras.Dv SIG_IGN , 133*2fe8fb19SBen Grasor a handler routine) and mask 134*2fe8fb19SBen Grasto be used when delivering the specified signal. 135*2fe8fb19SBen GrasFurther, if the 136*2fe8fb19SBen Gras.Dv SV_ONSTACK 137*2fe8fb19SBen Grasbit is set in 138*2fe8fb19SBen Gras.Fa sv_flags , 139*2fe8fb19SBen Grasthe system will deliver the signal to the process on a 140*2fe8fb19SBen Gras.Em "signal stack" , 141*2fe8fb19SBen Grasspecified with 142*2fe8fb19SBen Gras.Xr sigaltstack 2 . 143*2fe8fb19SBen GrasIf 144*2fe8fb19SBen Gras.Fa ovec 145*2fe8fb19SBen Grasis non-zero, the previous handling information for the signal 146*2fe8fb19SBen Grasis returned to the user. 147*2fe8fb19SBen Gras.Pp 148*2fe8fb19SBen GrasOnce a signal handler is installed, it remains installed 149*2fe8fb19SBen Grasuntil another 150*2fe8fb19SBen Gras.Fn sigvec 151*2fe8fb19SBen Grascall is made, or an 152*2fe8fb19SBen Gras.Xr execve 2 153*2fe8fb19SBen Grasis performed. 154*2fe8fb19SBen GrasA signal-specific default action may be reset by 155*2fe8fb19SBen Grassetting 156*2fe8fb19SBen Gras.Fa sv_handler 157*2fe8fb19SBen Grasto 158*2fe8fb19SBen Gras.Dv SIG_DFL . 159*2fe8fb19SBen GrasThe defaults are process termination, possibly with core dump; 160*2fe8fb19SBen Grasno action; stopping the process; or continuing the process. 161*2fe8fb19SBen GrasSee the signal list below for each signal's default action. 162*2fe8fb19SBen GrasIf 163*2fe8fb19SBen Gras.Fa sv_handler 164*2fe8fb19SBen Grasis set to 165*2fe8fb19SBen Gras.Dv SIG_DFL , 166*2fe8fb19SBen Grasthe default action for the signal is to discard the signal, 167*2fe8fb19SBen Grasand if a signal is pending, 168*2fe8fb19SBen Grasthe pending signal is discarded even if the signal is masked. 169*2fe8fb19SBen GrasIf 170*2fe8fb19SBen Gras.Fa sv_handler 171*2fe8fb19SBen Grasis set to 172*2fe8fb19SBen Gras.Dv SIG_IGN , 173*2fe8fb19SBen Grascurrent and pending instances 174*2fe8fb19SBen Grasof the signal are ignored and discarded. 175*2fe8fb19SBen Gras.Pp 176*2fe8fb19SBen GrasOptions may be specified by setting 177*2fe8fb19SBen Gras.Em sv_flags . 178*2fe8fb19SBen GrasIf the 179*2fe8fb19SBen Gras.Dv SV_ONSTACK 180*2fe8fb19SBen Grasbit is set in 181*2fe8fb19SBen Gras.Fa sv_flags , 182*2fe8fb19SBen Grasthe system will deliver the signal to the process on a 183*2fe8fb19SBen Gras.Em "signal stack" , 184*2fe8fb19SBen Grasspecified with 185*2fe8fb19SBen Gras.Xr sigstack 2 . 186*2fe8fb19SBen Gras.Pp 187*2fe8fb19SBen GrasIf a signal is caught during the system calls listed below, 188*2fe8fb19SBen Grasthe call may be restarted, 189*2fe8fb19SBen Grasthe call may return with a data transfer shorter than requested, 190*2fe8fb19SBen Grasor the call may be forced to terminate 191*2fe8fb19SBen Graswith the error 192*2fe8fb19SBen Gras.Dv EINTR . 193*2fe8fb19SBen GrasInterrupting of pending calls is requested 194*2fe8fb19SBen Grasby setting the 195*2fe8fb19SBen Gras.Dv SV_INTERRUPT 196*2fe8fb19SBen Grasbit in 197*2fe8fb19SBen Gras.Ar sv_flags . 198*2fe8fb19SBen GrasThe affected system calls include 199*2fe8fb19SBen Gras.Xr open 2 , 200*2fe8fb19SBen Gras.Xr read 2 , 201*2fe8fb19SBen Gras.Xr write 2 , 202*2fe8fb19SBen Gras.Xr sendto 2 , 203*2fe8fb19SBen Gras.Xr recvfrom 2 , 204*2fe8fb19SBen Gras.Xr sendmsg 2 205*2fe8fb19SBen Grasand 206*2fe8fb19SBen Gras.Xr recvmsg 2 207*2fe8fb19SBen Grason a communications channel or a slow device (such as a terminal, 208*2fe8fb19SBen Grasbut not a regular file) 209*2fe8fb19SBen Grasand during a 210*2fe8fb19SBen Gras.Xr wait 2 211*2fe8fb19SBen Grasor 212*2fe8fb19SBen Gras.Xr ioctl 2 . 213*2fe8fb19SBen GrasHowever, calls that have already committed are not restarted, 214*2fe8fb19SBen Grasbut instead return a partial success (for example, a short read count). 215*2fe8fb19SBen Gras.Pp 216*2fe8fb19SBen GrasAfter a 217*2fe8fb19SBen Gras.Xr fork 2 218*2fe8fb19SBen Grasor 219*2fe8fb19SBen Gras.Xr vfork 2 220*2fe8fb19SBen Grasall signals, the signal mask, the signal stack, 221*2fe8fb19SBen Grasand the interrupt/restart flags are inherited by the child. 222*2fe8fb19SBen Gras.Pp 223*2fe8fb19SBen GrasThe 224*2fe8fb19SBen Gras.Xr execve 2 225*2fe8fb19SBen Grassystem call reinstates the default action for all signals which 226*2fe8fb19SBen Graswere caught and resets all signals to be caught on the user stack. 227*2fe8fb19SBen GrasIgnored signals remain ignored; 228*2fe8fb19SBen Grasthe signal mask remains the same; 229*2fe8fb19SBen Grassignals that interrupt pending system calls continue to do so. 230*2fe8fb19SBen Gras.Pp 231*2fe8fb19SBen GrasSee 232*2fe8fb19SBen Gras.Xr signal 7 233*2fe8fb19SBen Grasfor comprehensive list of supported signals. 234*2fe8fb19SBen Gras.Sh NOTES 235*2fe8fb19SBen GrasThe mask specified in 236*2fe8fb19SBen Gras.Fa vec 237*2fe8fb19SBen Grasis not allowed to block 238*2fe8fb19SBen Gras.Dv SIGKILL 239*2fe8fb19SBen Grasor 240*2fe8fb19SBen Gras.Dv SIGSTOP . 241*2fe8fb19SBen GrasThis is enforced silently by the system. 242*2fe8fb19SBen Gras.Pp 243*2fe8fb19SBen GrasThe 244*2fe8fb19SBen Gras.Dv SV_INTERRUPT 245*2fe8fb19SBen Grasflag is not available in 246*2fe8fb19SBen Gras.Bx 4.2 , 247*2fe8fb19SBen Grashence it should not be used if backward compatibility is needed. 248*2fe8fb19SBen Gras.Sh RETURN VALUES 249*2fe8fb19SBen GrasA 0 value indicated that the call succeeded. 250*2fe8fb19SBen GrasA \-1 return value indicates an error occurred and 251*2fe8fb19SBen Gras.Va errno 252*2fe8fb19SBen Grasis set to indicated the reason. 253*2fe8fb19SBen Gras.Sh EXAMPLES 254*2fe8fb19SBen GrasThe handler routine can be declared: 255*2fe8fb19SBen Gras.Bd -literal -offset indent 256*2fe8fb19SBen Grasvoid 257*2fe8fb19SBen Grashandler(sig, code, scp) 258*2fe8fb19SBen Gras int sig, code; 259*2fe8fb19SBen Gras struct sigcontext *scp; 260*2fe8fb19SBen Gras.Ed 261*2fe8fb19SBen Gras.Pp 262*2fe8fb19SBen GrasHere 263*2fe8fb19SBen Gras.Fa sig 264*2fe8fb19SBen Grasis the signal number, into which the hardware faults and traps are 265*2fe8fb19SBen Grasmapped as defined below. 266*2fe8fb19SBen Gras.Fa code 267*2fe8fb19SBen Grasis a parameter that is either a constant 268*2fe8fb19SBen Grasor the code provided by the hardware. 269*2fe8fb19SBen Gras.Fa scp 270*2fe8fb19SBen Grasis a pointer to the 271*2fe8fb19SBen Gras.Fa sigcontext 272*2fe8fb19SBen Grasstructure (defined in 273*2fe8fb19SBen Gras.In signal.h ) , 274*2fe8fb19SBen Grasused to restore the context from before the signal. 275*2fe8fb19SBen Gras.Sh ERRORS 276*2fe8fb19SBen Gras.Fn sigvec 277*2fe8fb19SBen Graswill fail and no new signal handler will be installed if one 278*2fe8fb19SBen Grasof the following occurs: 279*2fe8fb19SBen Gras.Bl -tag -width Er 280*2fe8fb19SBen Gras.It Bq Er EFAULT 281*2fe8fb19SBen GrasEither 282*2fe8fb19SBen Gras.Fa vec 283*2fe8fb19SBen Grasor 284*2fe8fb19SBen Gras.Fa ovec 285*2fe8fb19SBen Graspoints to memory that is not a valid part of the process 286*2fe8fb19SBen Grasaddress space. 287*2fe8fb19SBen Gras.It Bq Er EINVAL 288*2fe8fb19SBen Gras.Fa sig 289*2fe8fb19SBen Grasis not a valid signal number. 290*2fe8fb19SBen Gras.It Bq Er EINVAL 291*2fe8fb19SBen GrasAn attempt is made to ignore or supply a handler for 292*2fe8fb19SBen Gras.Dv SIGKILL 293*2fe8fb19SBen Grasor 294*2fe8fb19SBen Gras.Dv SIGSTOP . 295*2fe8fb19SBen Gras.El 296*2fe8fb19SBen Gras.Sh SEE ALSO 297*2fe8fb19SBen Gras.Xr kill 1 , 298*2fe8fb19SBen Gras.Xr kill 2 , 299*2fe8fb19SBen Gras.Xr ptrace 2 , 300*2fe8fb19SBen Gras.Xr sigaction 2 , 301*2fe8fb19SBen Gras.Xr sigaltstack 2 , 302*2fe8fb19SBen Gras.Xr sigprocmask 2 , 303*2fe8fb19SBen Gras.Xr sigstack 2 , 304*2fe8fb19SBen Gras.Xr sigsuspend 2 , 305*2fe8fb19SBen Gras.Xr setjmp 3 , 306*2fe8fb19SBen Gras.Xr sigblock 3 , 307*2fe8fb19SBen Gras.Xr siginterrupt 3 , 308*2fe8fb19SBen Gras.Xr signal 3 , 309*2fe8fb19SBen Gras.Xr sigpause 3 , 310*2fe8fb19SBen Gras.Xr sigsetmask 3 , 311*2fe8fb19SBen Gras.Xr sigsetops 3 , 312*2fe8fb19SBen Gras.Xr tty 4 , 313*2fe8fb19SBen Gras.Xr signal 7 314