1 '\" te
   2 .\" Copyright (c) 2014, Ryan Zezeski.  All Rights Reserved.
   3 .\" Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
   4 .\" Copyright 1989 AT&T
   5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   8 .TH SIGACTION 2 "Oct 22, 2014"
   9 .SH NAME
  10 sigaction \- detailed signal management
  11 .SH SYNOPSIS
  12 .LP
  13 .nf
  14 #include <signal.h>
  15 
  16 \fBint\fR \fBsigaction\fR(\fBint\fR \fIsig\fR, \fBconst struct sigaction *restrict\fR \fIact\fR,
  17      \fBstruct sigaction *restrict\fR \fIoact\fR);
  18 .fi
  19 
  20 .SH DESCRIPTION
  21 .LP
  22 The \fBsigaction()\fR function allows the calling process to examine or specify
  23 the action to be taken on delivery of a specific signal. See
  24 \fBsignal.h\fR(3HEAD) for an explanation of general signal concepts.
  25 .sp
  26 .LP
  27 The \fIsig\fR argument specifies the signal and can be assigned any of the
  28 signals specified in \fBsignal.h\fR(3HEAD) except  \fBSIGKILL\fR and
  29 \fBSIGSTOP\fR.
  30 .sp
  31 .LP
  32 If the argument \fIact\fR is not \fINULL\fR, it points to a structure
  33 specifying the new action to be taken when delivering \fIsig\fR. If the
  34 argument \fIoact\fR is not \fINULL\fR, it points to a structure where the
  35 action previously associated with \fIsig\fR is to be stored on return from
  36 \fBsigaction()\fR.
  37 .sp
  38 .LP
  39 The \fBsigaction\fR structure includes the following members:
  40 .sp
  41 .in +2
  42 .nf
  43 void      (*sa_handler)(\|);
  44 void      (*sa_sigaction)(int, siginfo_t *, void *);
  45 sigset_t  sa_mask;
  46 int       sa_flags;
  47 .fi
  48 .in -2
  49 
  50 .sp
  51 .LP
  52 The storage occupied by \fBsa_handler\fR and \fBsa_sigaction\fR may overlap,
  53 and a standard-conforming application (see \fBstandards\fR(5)) must not use
  54 both simultaneously.
  55 .sp
  56 .LP
  57 The \fBsa_handler\fR member identifies the action to be associated with the
  58 specified signal, if the  \fBSA_SIGINFO\fR flag (see below) is cleared in the
  59 \fBsa_flags\fR field of the sigaction structure. It may take any of the values
  60 specified in \fBsignal.h\fR(3HEAD) or that of a user specified signal handler.
  61 If the  \fBSA_SIGINFO\fR flag is set in the \fBsa_flags\fR field, the
  62 \fBsa_sigaction\fR field specifies a signal-catching function.
  63 .sp
  64 .LP
  65 The \fBsa_mask\fR member specifies a set of signals to be blocked while the
  66 signal handler is active. On entry to the signal handler, that set of signals
  67 is added to the set of signals already being blocked when the signal is
  68 delivered. In addition, the signal that caused the handler to be executed will
  69 also be blocked, unless the  \fBSA_NODEFER\fR flag has been specified.
  70 \fBSIGSTOP\fR and  \fBSIGKILL\fR cannot be blocked (the system silently
  71 enforces this restriction).
  72 .sp
  73 .LP
  74 The \fBsa_flags\fR member specifies a set of flags used to modify the delivery
  75 of the signal. It is formed by a logical \fBOR\fR of any of the following
  76 values:
  77 .sp
  78 .ne 2
  79 .na
  80 \fB\fBSA_ONSTACK\fR\fR
  81 .ad
  82 .RS 16n
  83 If set and the signal is caught, and if the thread that is chosen to processes
  84 a delivered signal has an alternate signal stack declared with
  85 \fBsigaltstack\fR(2), then it will process the signal on that stack. Otherwise,
  86 the signal is delivered on the thread's normal stack.
  87 .RE
  88 
  89 .sp
  90 .ne 2
  91 .na
  92 \fB\fBSA_RESETHAND\fR\fR
  93 .ad
  94 .RS 16n
  95 If set and the signal is caught, the disposition of the signal is reset to
  96 \fBSIG_DFL\fR and the signal will not be blocked on entry to the signal handler
  97 (\fBSIGILL\fR, \fBSIGTRAP\fR, and \fBSIGPWR\fR cannot be  automatically reset
  98 when delivered; the system silently enforces this restriction).
  99 .RE
 100 
 101 .sp
 102 .ne 2
 103 .na
 104 \fB\fBSA_NODEFER\fR\fR
 105 .ad
 106 .RS 16n
 107 If set and the signal is caught, the signal will not be automatically
 108 blocked by the kernel while it is being caught.  Unless the signal is
 109 a realtime signal.  Multiple instances of the same realtime signal
 110 must be delivered in FIFO order and thus are always deferred.
 111 .RE
 112 
 113 .sp
 114 .ne 2
 115 .na
 116 \fB\fBSA_RESTART\fR\fR
 117 .ad
 118 .RS 16n
 119 If set and the signal is caught, functions that are interrupted by the
 120 execution of this signal's handler are transparently restarted by the system,
 121 namely \fBfcntl\fR(2), \fBioctl\fR(2), \fBwait\fR(3C), \fBwaitid\fR(2), and the
 122 following functions on slow devices like terminals: \fBgetmsg()\fR and
 123 \fBgetpmsg()\fR (see \fBgetmsg\fR(2));  \fBputmsg()\fR and \fBputpmsg()\fR (see
 124 \fBputmsg\fR(2)); \fBpread()\fR, \fBread()\fR, and \fBreadv()\fR (see
 125 \fBread\fR(2)); \fBpwrite()\fR, \fBwrite()\fR, and \fBwritev()\fR (see
 126 \fBwrite\fR(2)); \fBrecv()\fR, \fBrecvfrom()\fR, and \fBrecvmsg()\fR (see
 127 \fBrecv\fR(3SOCKET)); and \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR
 128 (see \fBsend\fR(3SOCKET)). Otherwise, the function returns an \fBEINTR\fR
 129 error.
 130 .RE
 131 
 132 .sp
 133 .ne 2
 134 .na
 135 \fB\fBSA_SIGINFO\fR\fR
 136 .ad
 137 .RS 16n
 138 If cleared and the signal is caught, \fIsig\fR is passed as the only argument
 139 to the signal-catching function. If set and the signal is caught,  two
 140 additional arguments are passed to the signal-catching function.  If the second
 141 argument is not equal to \fINULL\fR, it points to a \fBsiginfo_t\fR structure
 142 containing the reason why the signal was generated (see
 143 \fBsiginfo.h\fR(3HEAD)); the third argument points to a \fBucontext_t\fR
 144 structure containing the receiving process's context when the signal was
 145 delivered (see \fBucontext.h\fR(3HEAD)).
 146 .RE
 147 
 148 .sp
 149 .ne 2
 150 .na
 151 \fB\fBSA_NOCLDWAIT\fR\fR
 152 .ad
 153 .RS 16n
 154 If set and \fIsig\fR equals  \fBSIGCHLD\fR, the system will not create zombie
 155 processes when children of the calling process exit. If the calling process
 156 subsequently issues a \fBwait\fR(3C), it blocks until all of the calling
 157 process's child processes terminate, and then returns \fB\(mi1\fR with
 158 \fBerrno\fR set to \fBECHILD\fR.
 159 .RE
 160 
 161 .sp
 162 .ne 2
 163 .na
 164 \fB\fBSA_NOCLDSTOP\fR\fR
 165 .ad
 166 .RS 16n
 167 If set and \fIsig\fR equals \fBSIGCHLD\fR, \fBSIGCHLD\fR will not be sent to
 168 the calling process when its child processes stop or continue.
 169 .RE
 170 
 171 .SH RETURN VALUES
 172 .LP
 173 Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
 174 returned, \fBerrno\fR is set to indicate the error, and no new signal handler
 175 is installed.
 176 .SH ERRORS
 177 .LP
 178 The \fBsigaction()\fR function will fail if:
 179 .sp
 180 .ne 2
 181 .na
 182 \fB\fBEINVAL\fR\fR
 183 .ad
 184 .RS 10n
 185 The value of the \fIsig\fR argument is not a valid signal number or is equal to
 186 \fBSIGKILL\fR or \fBSIGSTOP\fR. In addition, if in a multithreaded process, it
 187 is equal to \fBSIGWAITING\fR, \fBSIGCANCEL\fR, or \fBSIGLWP\fR.
 188 .RE
 189 
 190 .SH ATTRIBUTES
 191 .LP
 192 See \fBattributes\fR(5) for descriptions of the following attributes:
 193 .sp
 194 
 195 .sp
 196 .TS
 197 box;
 198 c | c
 199 l | l .
 200 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 201 _
 202 Interface Stability     Committed
 203 _
 204 MT-Level        Async-Signal-Safe
 205 _
 206 Standard        See \fBstandards\fR(5).
 207 .TE
 208 
 209 .SH SEE ALSO
 210 .LP
 211 \fBkill\fR(1), \fBIntro\fR(2), \fBexit\fR(2), \fBfcntl\fR(2), \fBgetmsg\fR(2),
 212 \fBioctl\fR(2), \fBkill\fR(2), \fBpause\fR(2), \fBputmsg\fR(2), \fBread\fR(2),
 213 \fBsigaltstack\fR(2), \fBsigprocmask\fR(2), \fBsigsend\fR(2),
 214 \fBsigsuspend\fR(2), \fBwaitid\fR(2), \fBwrite\fR(2), \fBrecv\fR(3SOCKET),
 215 \fBsend\fR(3SOCKET), \fBsiginfo.h\fR(3HEAD), \fBsignal\fR(3C),
 216 \fBsignal.h\fR(3HEAD), \fBsigsetops\fR(3C), \fBucontext.h\fR(3HEAD),
 217 \fBwait\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)
 218 .SH NOTES
 219 .LP
 220 The handler routine can be declared:
 221 .sp
 222 .in +2
 223 .nf
 224 void handler (int \fIsig\fR, siginfo_t *\fIsip\fR, ucontext_t *\fIucp\fR);
 225 .fi
 226 .in -2
 227 
 228 .sp
 229 .LP
 230 The \fIsig\fR argument is the signal number. The \fIsip\fR argument is a
 231 pointer (to space on the stack) to a \fBsiginfo_t\fR structure, which provides
 232 additional detail about the delivery of the signal. The \fIucp\fR argument is a
 233 pointer (again to space on the stack) to a \fBucontext_t\fR structure (defined
 234 in <\fBsys/ucontext.h\fR>) which contains the context from before the signal.
 235 It is not recommended that \fIucp\fR be used by the handler to restore the
 236 context from before the signal delivery.