xref: /csrg-svn/lib/libc/compat-43/sigvec.2 (revision 66934)
160986Sbostic.\" Copyright (c) 1980, 1991, 1993
260986Sbostic.\"	The Regents of the University of California.  All rights reserved.
320135Smckusick.\"
443569Strent.\" %sccs.include.redist.man%
520135Smckusick.\"
6*66934Sbostic.\"     @(#)sigvec.2	8.2 (Berkeley) 04/19/94
738053Sbostic.\"
848836Scael.Dd
948836Scael.Dt SIGVEC 2
1048836Scael.Os BSD 4
1148836Scael.Sh NAME
1248836Scael.Nm sigvec
1348836Scael.Nd software signal facilities
1448836Scael.Sh SYNOPSIS
1548836Scael.Fd #include <signal.h>
1648836Scael.Bd -literal
1748836Scaelstruct sigvec {
1848836Scael        void     (*sv_handler)();
1948836Scael	sigset_t sv_mask;
2048836Scael	int      sv_flags;
2148836Scael};
2248836Scael.Ed
2348836Scael.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec"
2448836Scael.Sh DESCRIPTION
2548836Scael.Bf -symbolic
2648836ScaelThis interface is made obsolete by sigaction(2).
2748836Scael.Ef
2848836Scael.Pp
2920136SmckusickThe system defines a set of signals that may be delivered to a process.
30*66934SbosticSignal delivery resembles the occurrence of a hardware interrupt:
3120136Smckusickthe signal is blocked from further occurrence, the current process
3220136Smckusickcontext is saved, and a new one is built.  A process may specify a
3348836Scael.Em handler
3420136Smckusickto which a signal is delivered, or specify that a signal is to be
3548836Scael.Em blocked
3620136Smckusickor
3748836Scael.Em ignored .
3820136SmckusickA process may also specify that a default action is to be taken
3920136Smckusickby the system when a signal occurs.
4020136SmckusickNormally, signal handlers execute on the current stack
4120136Smckusickof the process.  This may be changed, on a per-handler basis,
4220136Smckusickso that signals are taken on a special
4348836Scael.Em "signal stack" .
4448836Scael.Pp
4520136SmckusickAll signals have the same
4648836Scael.Em priority .
4720136SmckusickSignal routines execute with the signal that caused their
4820136Smckusickinvocation
4948836Scael.Em blocked ,
5020136Smckusickbut other signals may yet occur.
5120136SmckusickA global
5248836Scael.Em "signal mask"
5320136Smckusickdefines the set of signals currently blocked from delivery
5420137Smckusickto a process.  The signal mask for a process is initialized
5520136Smckusickfrom that of its parent (normally 0).  It
5620136Smckusickmay be changed with a
5748836Scael.Xr sigblock 2
5820136Smckusickor
5948836Scael.Xr sigsetmask 2
6020136Smckusickcall, or when a signal is delivered to the process.
6148836Scael.Pp
6220136SmckusickWhen a signal
6320136Smckusickcondition arises for a process, the signal is added to a set of
6420136Smckusicksignals pending for the process.  If the signal is not currently
6548836Scael.Em blocked
6620136Smckusickby the process then it is delivered to the process.  When a signal
6720136Smckusickis delivered, the current state of the process is saved,
6820136Smckusicka new signal mask is calculated (as described below),
6920136Smckusickand the signal handler is invoked.  The call to the handler
7020136Smckusickis arranged so that if the signal handling routine returns
7120136Smckusicknormally the process will resume execution in the context
7220136Smckusickfrom before the signal's delivery.
7320136SmckusickIf the process wishes to resume in a different context, then it
7420136Smckusickmust arrange to restore the previous context itself.
7548836Scael.Pp
7620136SmckusickWhen a signal is delivered to a process a new signal mask is
7720136Smckusickinstalled for the duration of the process' signal handler
7820136Smckusick(or until a
7948836Scael.Xr sigblock
8020136Smckusickor
8148836Scael.Xr sigsetmask
8220136Smckusickcall is made).
8320136SmckusickThis mask is formed by taking the current signal mask,
8420136Smckusickadding the signal to be delivered, and
8548836Scael.Em or Ns 'ing
8620136Smckusickin the signal mask associated with the handler to be invoked.
8748836Scael.Pp
8848836Scael.Fn Sigvec
8920136Smckusickassigns a handler for a specific signal.  If
9048836Scael.Fa vec
9120136Smckusickis non-zero, it
9220136Smckusickspecifies a handler routine and mask
9320137Smckusickto be used when delivering the specified signal.
9448836ScaelFurther, if the
9548836Scael.Dv SV_ONSTACK
9648836Scaelbit is set in
9748836Scael.Fa sv_flags ,
9820137Smckusickthe system will deliver the signal to the process on a
9948836Scael.Em "signal stack" ,
10020136Smckusickspecified with
10153258Sbostic.Xr sigaltstack 2 .
10220136SmckusickIf
10348836Scael.Fa ovec
10420136Smckusickis non-zero, the previous handling information for the signal
10520136Smckusickis returned to the user.
10648836Scael.Pp
10720136SmckusickThe following is a list of all signals
10820136Smckusickwith names as in the include file
10948836Scael.Aq Pa signal.h :
11048836Scael.Bl -column SIGVTALARMXX "create core imagexxx"
11148836Scael.It Sy "  NAME  " "	  Default Action  " "	              Description"
11248836Scael.It Dv SIGHUP No "	terminate process" "	terminal line hangup"
11348836Scael.It Dv SIGINT No "	terminate process" "	interrupt program"
11448836Scael.It Dv SIGQUIT No "	create core image" "	quit program"
11548836Scael.It Dv SIGILL No "	create core image" "	illegal instruction"
11648836Scael.It Dv SIGTRAP No "	create core image" "	trace trap"
11748836Scael.It Dv SIGABRT No "	create core image" Xr 	abort 2
11848836Scaelcall (formerly
11948836Scael.Dv SIGIOT )
12048836Scael.It Dv SIGEMT No "	create core image" "	emulate instruction executed"
12148836Scael.It Dv SIGFPE No "	create core image" "	floating-point exception"
12248836Scael.It Dv SIGKILL No "	terminate process" "	kill program"
12348836Scael.It Dv SIGBUS No "	create core image" "	bus error"
12448836Scael.It Dv SIGSEGV No "	create core image" "	segmentation violation"
12548836Scael.It Dv SIGSYS No "	create core image" "	system call given invalid argument"
12648836Scael.It Dv SIGPIPE No "	terminate process" "	write on a pipe with no reader"
12748836Scael.It Dv SIGALRM No "	terminate process" "	real-time timer expired"
12848836Scael.It Dv SIGTERM No "	terminate process" "	software termination signal"
12948836Scael.It Dv SIGURG No "	discard signal" "	urgent condition present on socket"
13048836Scael.It Dv SIGSTOP No "	stop process" "	stop (cannot be caught or ignored)"
13148836Scael.It Dv SIGTSTP No "	stop process" "	stop signal generated from keyboard"
13248836Scael.It Dv SIGCONT No "	discard signal" "	continue after stop"
13348836Scael.It Dv SIGCHLD No "	discard signal" "	child status has changed"
13448836Scael.It Dv SIGTTIN No "	stop process" "	background read attempted from control terminal"
13548836Scael.It Dv SIGTTOU No "	stop process" "	background write attempted to control terminal"
13648836Scael.It Dv SIGIO No "	discard signal" Tn "	I/O"
13748836Scaelis possible on a descriptor (see
13848836Scael.Xr fcntl 2 )
13948836Scael.It Dv SIGXCPU No "	terminate process" "	cpu time limit exceeded (see"
14048836Scael.Xr setrlimit 2 )
14148836Scael.It Dv SIGXFSZ No "	terminate process" "	file size limit exceeded (see"
14248836Scael.Xr setrlimit 2 )
14348836Scael.It Dv SIGVTALRM No "	terminate process" "	virtual time alarm (see"
14448836Scael.Xr setitimer 2 )
14548836Scael.It Dv SIGPROF No "	terminate process" "	profiling timer alarm (see"
14648836Scael.Xr setitimer 2 )
14748836Scael.It Dv SIGWINCH No "	discard signal" "	Window size change"
14848836Scael.It Dv SIGINFO No "	discard signal" "	status request from keyboard"
14948836Scael.It Dv SIGUSR1 No "	terminate process" "	User defined signal 1"
15048836Scael.It Dv SIGUSR2 No "	terminate process" "	User defined signal 2"
15148836Scael.El
15248836Scael.Pp
15320136SmckusickOnce a signal handler is installed, it remains installed
15420136Smckusickuntil another
15548836Scael.Fn sigvec
15648836Scaelcall is made, or an
15748836Scael.Xr execve 2
15820136Smckusickis performed.
15948836ScaelA signal-specific default action may be reset by
16048836Scaelsetting
16148836Scael.Fa sv_handler
16248836Scaelto
16348836Scael.Dv SIG_DFL .
16448836ScaelThe defaults are process termination, possibly with core dump;
16548836Scaelno action; stopping the process; or continuing the process.
16648836ScaelSee the above signal list for each signal's default action.
16720135SmckusickIf
16848836Scael.Fa sv_handler
16948836Scaelis
17048836Scael.Dv SIG_IGN
17148836Scaelcurrent and pending instances
17248836Scaelof the signal are ignored and discarded.
17348836Scael.Pp
17448836ScaelIf a signal is caught during the system calls listed below,
17520137Smckusickthe call is normally restarted.
17620137SmckusickThe call can be forced to terminate prematurely with an
17748836Scael.Dv EINTR
17848836Scaelerror return by setting the
17948836Scael.Dv SV_INTERRUPT
18048836Scaelbit in
18148836Scael.Fa sv_flags .
18244872SkarelsThe affected system calls include
18348836Scael.Xr read 2 ,
18448836Scael.Xr write 2 ,
18548836Scael.Xr sendto 2 ,
18648836Scael.Xr recvfrom 2 ,
18748836Scael.Xr sendmsg 2
18844872Skarelsand
18948836Scael.Xr recvmsg 2
19044872Skarelson a communications channel or a slow device (such as a terminal,
19144872Skarelsbut not a regular file)
19244872Skarelsand during a
19348836Scael.Xr wait 2
19420135Smckusickor
19548836Scael.Xr ioctl 2 .
19644872SkarelsHowever, calls that have already committed are not restarted,
19744872Skarelsbut instead return a partial success (for example, a short read count).
19848836Scael.Pp
19920135SmckusickAfter a
20048836Scael.Xr fork 2
20120135Smckusickor
20248836Scael.Xr vfork 2
20320137Smckusickall signals, the signal mask, the signal stack,
20448836Scaeland the restart/interrupt flags are inherited by the child.
20548836Scael.Pp
20648836Scael.Xr Execve 2
20748836Scaelreinstates the default
20848836Scaelaction for all signals which were caught and
20920137Smckusickresets all signals to be caught on the user stack.
21020137SmckusickIgnored signals remain ignored;
21120137Smckusickthe signal mask remains the same;
21220137Smckusicksignals that interrupt system calls continue to do so.
21348836Scael.Sh NOTES
21420136SmckusickThe mask specified in
21548836Scael.Fa vec
21648836Scaelis not allowed to block
21748836Scael.Dv SIGKILL
21848836Scaelor
21948836Scael.Dv SIGSTOP .
22044872SkarelsThis is done silently by the system.
22148836Scael.Pp
22248836ScaelThe
22348836Scael.Dv SV_INTERRUPT
22448836Scaelflag is not available in
22548836Scael.Bx 4.2 ,
22620137Smckusickhence it should not be used if backward compatibility is needed.
22748836Scael.Sh RETURN VALUES
22820136SmckusickA 0 value indicated that the call succeeded.  A \-1 return value
22920137Smckusickindicates an error occurred and
23048836Scael.Va errno
23120136Smckusickis set to indicated the reason.
23248836Scael.Sh ERRORS
23348836Scael.Fn Sigvec
23420136Smckusickwill fail and no new signal handler will be installed if one
23520136Smckusickof the following occurs:
23648836Scael.Bl -tag -width [EINVAL]
23748836Scael.It Bq Er EFAULT
23820136SmckusickEither
23948836Scael.Fa vec
24020136Smckusickor
24148836Scael.Fa ovec
24223823Ssechrestpoints to memory that is not a valid part of the process
24320136Smckusickaddress space.
24448836Scael.It Bq Er EINVAL
24548836Scael.Fa Sig
24620136Smckusickis not a valid signal number.
24748836Scael.It Bq Er EINVAL
24848836ScaelAn attempt is made to ignore or supply a handler for
24948836Scael.Dv SIGKILL
25048836Scaelor
25148836Scael.Dv SIGSTOP .
25248836Scael.El
25348836Scael.Sh SEE ALSO
25448836Scael.Xr kill 1 ,
25552762Sbostic.Xr kill 2 ,
25648836Scael.Xr ptrace 2 ,
25752762Sbostic.Xr sigaction 2 ,
25853258Sbostic.Xr sigaltstack 2 ,
25952762Sbostic.Xr sigblock 2 ,
26052762Sbostic.Xr sigpause 2 ,
26148836Scael.Xr sigprocmask 2 ,
26248836Scael.Xr sigsetmask 2 ,
26352762Sbostic.Xr sigsuspend 2 ,
26448836Scael.Xr setjmp 3 ,
26548836Scael.Xr siginterrupt 3 ,
26652762Sbostic.Xr signal 3,
26752762Sbostic.Xr sigsetops 3 ,
26848836Scael.Xr tty 4
26948836Scael.Sh EXAMPLE
27048836ScaelOn the
27148836Scael.Tn VAX\-11
27220135SmckusickThe handler routine can be declared:
27348836Scael.Bd -literal -offset indent
27448836Scaelvoid handler(sig, code, scp)
27548836Scaelint sig, code;
27648836Scaelstruct sigcontext *scp;
27748836Scael.Ed
27848836Scael.Pp
27920135SmckusickHere
28048836Scael.Fa sig
28120136Smckusickis the signal number, into which the hardware faults and traps are
28220136Smckusickmapped as defined below.
28348836Scael.Fa Code
28423823Ssechrestis a parameter that is either a constant
28520135Smckusickas given below or, for compatibility mode faults, the code provided by
28620136Smckusickthe hardware (Compatibility mode faults are distinguished from the
28748836Scaelother
28848836Scael.Dv SIGILL
28948836Scaeltraps by having
29048836Scael.Dv PSL_CM
29148836Scaelset in the psl).
29248836Scael.Fa Scp
29320136Smckusickis a pointer to the
29448836Scael.Fa sigcontext
29520136Smckusickstructure (defined in
29648836Scael.Aq Pa signal.h ) ,
29720136Smckusickused to restore the context from before the signal.
29848836Scael.Sh BUGS
29920137SmckusickThis manual page is still confusing.
300