1SIGACTION(2)               Linux Programmer's Manual              SIGACTION(2)
2
3
4

NAME

6       sigaction, rt_sigaction - examine and change a signal action
7

SYNOPSIS

9       #include <signal.h>
10
11       int sigaction(int signum, const struct sigaction *restrict act,
12                     struct sigaction *restrict oldact);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       sigaction():
17           _POSIX_C_SOURCE
18
19       siginfo_t:
20           _POSIX_C_SOURCE >= 199309L
21

DESCRIPTION

23       The  sigaction()  system  call  is used to change the action taken by a
24       process on receipt of a specific signal.  (See signal(7) for  an  over‐
25       view of signals.)
26
27       signum  specifies the signal and can be any valid signal except SIGKILL
28       and SIGSTOP.
29
30       If act is non-NULL, the new action for signal signum is installed  from
31       act.  If oldact is non-NULL, the previous action is saved in oldact.
32
33       The sigaction structure is defined as something like:
34
35           struct sigaction {
36               void     (*sa_handler)(int);
37               void     (*sa_sigaction)(int, siginfo_t *, void *);
38               sigset_t   sa_mask;
39               int        sa_flags;
40               void     (*sa_restorer)(void);
41           };
42
43       On  some  architectures  a  union  is  involved:  do not assign to both
44       sa_handler and sa_sigaction.
45
46       The sa_restorer field is not intended for application use.  (POSIX does
47       not  specify a sa_restorer field.)  Some further details of the purpose
48       of this field can be found in sigreturn(2).
49
50       sa_handler specifies the action to be associated with signum and is  be
51       one of the following:
52
53       * SIG_DFL for the default action.
54
55       * SIG_IGN to ignore this signal.
56
57       * A  pointer to a signal handling function.  This function receives the
58         signal number as its only argument.
59
60       If SA_SIGINFO is specified in sa_flags, then sa_sigaction  (instead  of
61       sa_handler)  specifies  the  signal-handling function for signum.  This
62       function receives three arguments, as described below.
63
64       sa_mask specifies a mask of signals  which  should  be  blocked  (i.e.,
65       added  to  the signal mask of the thread in which the signal handler is
66       invoked) during execution of the signal handler.  In addition, the sig‐
67       nal  which triggered the handler will be blocked, unless the SA_NODEFER
68       flag is used.
69
70       sa_flags specifies a set of flags which modify the behavior of the sig‐
71       nal.  It is formed by the bitwise OR of zero or more of the following:
72
73       SA_NOCLDSTOP
74              If  signum  is  SIGCHLD,  do not receive notification when child
75              processes stop (i.e., when they receive one of SIGSTOP, SIGTSTP,
76              SIGTTIN, or SIGTTOU) or resume (i.e., they receive SIGCONT) (see
77              wait(2)).  This flag is meaningful only when establishing a han‐
78              dler for SIGCHLD.
79
80       SA_NOCLDWAIT (since Linux 2.6)
81              If  signum  is  SIGCHLD,  do not transform children into zombies
82              when they terminate.  See also waitpid(2).  This flag  is  mean‐
83              ingful  only  when  establishing  a handler for SIGCHLD, or when
84              setting that signal's disposition to SIG_DFL.
85
86              If the SA_NOCLDWAIT flag is set when establishing a handler  for
87              SIGCHLD,  POSIX.1 leaves it unspecified whether a SIGCHLD signal
88              is generated when a  child  process  terminates.   On  Linux,  a
89              SIGCHLD  signal  is generated in this case; on some other imple‐
90              mentations, it is not.
91
92       SA_NODEFER
93              Do not add the signal to the thread's signal mask while the han‐
94              dler   is   executing,   unless   the  signal  is  specified  in
95              act.sa_mask.  Consequently, a further instance of the signal may
96              be  delivered  to  the thread while it is executing the handler.
97              This flag is meaningful only when establishing a signal handler.
98
99              SA_NOMASK is an obsolete, nonstandard synonym for this flag.
100
101       SA_ONSTACK
102              Call the signal handler on an alternate signal stack provided by
103              sigaltstack(2).  If an alternate stack is not available, the de‐
104              fault stack will be used.  This flag is meaningful only when es‐
105              tablishing a signal handler.
106
107       SA_RESETHAND
108              Restore  the signal action to the default upon entry to the sig‐
109              nal handler.  This flag is meaningful only when  establishing  a
110              signal handler.
111
112              SA_ONESHOT is an obsolete, nonstandard synonym for this flag.
113
114       SA_RESTART
115              Provide  behavior compatible with BSD signal semantics by making
116              certain system calls restartable across signals.  This  flag  is
117              meaningful  only  when  establishing a signal handler.  See sig‐
118              nal(7) for a discussion of system call restarting.
119
120       SA_RESTORER
121              Not intended for application use.  This flag is used  by  C  li‐
122              braries  to indicate that the sa_restorer field contains the ad‐
123              dress of a "signal trampoline".  See sigreturn(2) for  more  de‐
124              tails.
125
126       SA_SIGINFO (since Linux 2.2)
127              The  signal  handler  takes  three  arguments, not one.  In this
128              case, sa_sigaction should be set instead  of  sa_handler.   This
129              flag is meaningful only when establishing a signal handler.
130
131       SA_UNSUPPORTED (since Linux 5.11)
132              Used to dynamically probe for flag bit support.
133
134              If  an attempt to register a handler succeeds with this flag set
135              in act->sa_flags alongside other flags that are potentially  un‐
136              supported  by  the  kernel, and an immediately subsequent sigac‐
137              tion() call specifying the same signal number and  with  a  non-
138              NULL    oldact   argument   yields   SA_UNSUPPORTED   clear   in
139              oldact->sa_flags, then oldact->sa_flags may be used as a bitmask
140              describing  which  of  the potentially unsupported flags are, in
141              fact, supported.  See the section "Dynamically probing for  flag
142              bit support" below for more details.
143
144       SA_EXPOSE_TAGBITS (since Linux 5.11)
145              Normally, when delivering a signal, an architecture-specific set
146              of tag bits are cleared from the si_addr field of siginfo_t.  If
147              this  flag  is  set,  an architecture-specific subset of the tag
148              bits will be preserved in si_addr.
149
150              Programs that need to be compatible with  Linux  versions  older
151              than 5.11 must use SA_UNSUPPORTED to probe for support.
152
153   The siginfo_t argument to a SA_SIGINFO handler
154       When  the SA_SIGINFO flag is specified in act.sa_flags, the signal han‐
155       dler address is passed via the act.sa_sigaction  field.   This  handler
156       takes three arguments, as follows:
157
158           void
159           handler(int sig, siginfo_t *info, void *ucontext)
160           {
161               ...
162           }
163
164       These three arguments are as follows
165
166       sig    The number of the signal that caused invocation of the handler.
167
168       info   A  pointer  to a siginfo_t, which is a structure containing fur‐
169              ther information about the signal, as described below.
170
171       ucontext
172              This is a pointer to a ucontext_t  structure,  cast  to  void *.
173              The  structure  pointed to by this field contains signal context
174              information that was saved on the user-space stack by  the  ker‐
175              nel;  for  details, see sigreturn(2).  Further information about
176              the ucontext_t structure can be found in getcontext(3) and  sig‐
177              nal(7).   Commonly, the handler function doesn't make any use of
178              the third argument.
179
180       The siginfo_t data type is a structure with the following fields:
181
182           siginfo_t {
183               int      si_signo;     /* Signal number */
184               int      si_errno;     /* An errno value */
185               int      si_code;      /* Signal code */
186               int      si_trapno;    /* Trap number that caused
187                                         hardware-generated signal
188                                         (unused on most architectures) */
189               pid_t    si_pid;       /* Sending process ID */
190               uid_t    si_uid;       /* Real user ID of sending process */
191               int      si_status;    /* Exit value or signal */
192               clock_t  si_utime;     /* User time consumed */
193               clock_t  si_stime;     /* System time consumed */
194               union sigval si_value; /* Signal value */
195               int      si_int;       /* POSIX.1b signal */
196               void    *si_ptr;       /* POSIX.1b signal */
197               int      si_overrun;   /* Timer overrun count;
198                                         POSIX.1b timers */
199               int      si_timerid;   /* Timer ID; POSIX.1b timers */
200               void    *si_addr;      /* Memory location which caused fault */
201               long     si_band;      /* Band event (was int in
202                                         glibc 2.3.2 and earlier) */
203               int      si_fd;        /* File descriptor */
204               short    si_addr_lsb;  /* Least significant bit of address
205                                         (since Linux 2.6.32) */
206               void    *si_lower;     /* Lower bound when address violation
207                                         occurred (since Linux 3.19) */
208               void    *si_upper;     /* Upper bound when address violation
209                                         occurred (since Linux 3.19) */
210               int      si_pkey;      /* Protection key on PTE that caused
211                                         fault (since Linux 4.6) */
212               void    *si_call_addr; /* Address of system call instruction
213                                         (since Linux 3.5) */
214               int      si_syscall;   /* Number of attempted system call
215                                         (since Linux 3.5) */
216               unsigned int si_arch;  /* Architecture of attempted system call
217                                         (since Linux 3.5) */
218           }
219
220       si_signo, si_errno and si_code are defined for all signals.   (si_errno
221       is  generally unused on Linux.)  The rest of the struct may be a union,
222       so that one should read only the fields that  are  meaningful  for  the
223       given signal:
224
225       * Signals  sent with kill(2) and sigqueue(3) fill in si_pid and si_uid.
226         In addition, signals sent with sigqueue(3) fill in si_int and  si_ptr
227         with   the  values  specified  by  the  sender  of  the  signal;  see
228         sigqueue(3) for more details.
229
230       * Signals sent by POSIX.1b timers (since Linux 2.6) fill in  si_overrun
231         and  si_timerid.   The si_timerid field is an internal ID used by the
232         kernel to identify the timer; it is not the same as the timer ID  re‐
233         turned by timer_create(2).  The si_overrun field is the timer overrun
234         count; this is the same information as  is  obtained  by  a  call  to
235         timer_getoverrun(2).  These fields are nonstandard Linux extensions.
236
237       * Signals  sent  for message queue notification (see the description of
238         SIGEV_SIGNAL  in  mq_notify(3))  fill  in  si_int/si_ptr,  with   the
239         sigev_value  supplied to mq_notify(3); si_pid, with the process ID of
240         the message sender; and si_uid, with the real user ID of the  message
241         sender.
242
243       * SIGCHLD  fills  in si_pid, si_uid, si_status, si_utime, and si_stime,
244         providing information about the  child.   The  si_pid  field  is  the
245         process  ID  of  the  child; si_uid is the child's real user ID.  The
246         si_status field contains the exit status of the child (if si_code  is
247         CLD_EXITED),  or  the signal number that caused the process to change
248         state.  The si_utime and si_stime contain the  user  and  system  CPU
249         time used by the child process; these fields do not include the times
250         used by waited-for children (unlike getrusage(2) and  times(2)).   In
251         kernels  up to 2.6, and since 2.6.27, these fields report CPU time in
252         units of sysconf(_SC_CLK_TCK).  In 2.6 kernels before 2.6.27,  a  bug
253         meant  that these fields reported time in units of the (configurable)
254         system jiffy (see time(7)).
255
256       * SIGILL, SIGFPE, SIGSEGV, SIGBUS, and SIGTRAP fill in si_addr with the
257         address of the fault.  On some architectures, these signals also fill
258         in the si_trapno field.
259
260         Some  suberrors  of   SIGBUS,   in   particular   BUS_MCEERR_AO   and
261         BUS_MCEERR_AR,  also  fill  in si_addr_lsb.  This field indicates the
262         least significant bit of the reported address and therefore  the  ex‐
263         tent  of  the corruption.  For example, if a full page was corrupted,
264         si_addr_lsb contains log2(sysconf(_SC_PAGESIZE)).   When  SIGTRAP  is
265         delivered  in  response  to  a  ptrace(2)  event  (PTRACE_EVENT_foo),
266         si_addr is not populated, but si_pid and si_uid  are  populated  with
267         the  respective process ID and user ID responsible for delivering the
268         trap.  In the case of seccomp(2), the tracee will be shown as  deliv‐
269         ering the event.  BUS_MCEERR_* and si_addr_lsb are Linux-specific ex‐
270         tensions.
271
272         The SEGV_BNDERR suberror of SIGSEGV populates si_lower and si_upper.
273
274         The SEGV_PKUERR suberror of SIGSEGV populates si_pkey.
275
276       * SIGIO/SIGPOLL (the two names are synonyms on Linux) fills in  si_band
277         and  si_fd.  The si_band event is a bit mask containing the same val‐
278         ues as are filled in the revents field by poll(2).  The  si_fd  field
279         indicates  the  file descriptor for which the I/O event occurred; for
280         further details, see the description of F_SETSIG in fcntl(2).
281
282       * SIGSYS, generated (since Linux 3.5) when  a  seccomp  filter  returns
283         SECCOMP_RET_TRAP,  fills in si_call_addr, si_syscall, si_arch, si_er‐
284         rno, and other fields as described in seccomp(2).
285
286   The si_code field
287       The si_code field inside the siginfo_t argument that  is  passed  to  a
288       SA_SIGINFO  signal  handler  is a value (not a bit mask) indicating why
289       this signal was sent.  For a ptrace(2) event, si_code will contain SIG‐
290       TRAP and have the ptrace event in the high byte:
291
292           (SIGTRAP | PTRACE_EVENT_foo << 8).
293
294       For  a  non-ptrace(2)  event, the values that can appear in si_code are
295       described in the remainder of this section.  Since glibc 2.20, the def‐
296       initions  of  most  of  these  symbols  are obtained from <signal.h> by
297       defining feature test macros (before including any header file) as fol‐
298       lows:
299
300       *  _XOPEN_SOURCE with the value 500 or greater;
301
302       *  _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED; or
303
304       *  _POSIX_C_SOURCE with the value 200809L or greater.
305
306       For  the  TRAP_* constants, the symbol definitions are provided only in
307       the first two cases.  Before glibc 2.20, no feature  test  macros  were
308       required to obtain these symbols.
309
310       For  a regular signal, the following list shows the values which can be
311       placed in si_code for any signal, along with the reason that the signal
312       was generated.
313
314           SI_USER
315                  kill(2).
316
317           SI_KERNEL
318                  Sent by the kernel.
319
320           SI_QUEUE
321                  sigqueue(3).
322
323           SI_TIMER
324                  POSIX timer expired.
325
326           SI_MESGQ (since Linux 2.6.6)
327                  POSIX message queue state changed; see mq_notify(3).
328
329           SI_ASYNCIO
330                  AIO completed.
331
332           SI_SIGIO
333                  Queued  SIGIO  (only  in kernels up to Linux 2.2; from Linux
334                  2.4 onward SIGIO/SIGPOLL fills in si_code as  described  be‐
335                  low).
336
337           SI_TKILL (since Linux 2.4.19)
338                  tkill(2) or tgkill(2).
339
340       The following values can be placed in si_code for a SIGILL signal:
341
342           ILL_ILLOPC
343                  Illegal opcode.
344
345           ILL_ILLOPN
346                  Illegal operand.
347
348           ILL_ILLADR
349                  Illegal addressing mode.
350
351           ILL_ILLTRP
352                  Illegal trap.
353
354           ILL_PRVOPC
355                  Privileged opcode.
356
357           ILL_PRVREG
358                  Privileged register.
359
360           ILL_COPROC
361                  Coprocessor error.
362
363           ILL_BADSTK
364                  Internal stack error.
365
366       The following values can be placed in si_code for a SIGFPE signal:
367
368           FPE_INTDIV
369                  Integer divide by zero.
370
371           FPE_INTOVF
372                  Integer overflow.
373
374           FPE_FLTDIV
375                  Floating-point divide by zero.
376
377           FPE_FLTOVF
378                  Floating-point overflow.
379
380           FPE_FLTUND
381                  Floating-point underflow.
382
383           FPE_FLTRES
384                  Floating-point inexact result.
385
386           FPE_FLTINV
387                  Floating-point invalid operation.
388
389           FPE_FLTSUB
390                  Subscript out of range.
391
392       The following values can be placed in si_code for a SIGSEGV signal:
393
394           SEGV_MAPERR
395                  Address not mapped to object.
396
397           SEGV_ACCERR
398                  Invalid permissions for mapped object.
399
400           SEGV_BNDERR (since Linux 3.19)
401                  Failed address bound checks.
402
403           SEGV_PKUERR (since Linux 4.6)
404                  Access  was denied by memory protection keys.  See pkeys(7).
405                  The protection key which applied to this access is available
406                  via si_pkey.
407
408       The following values can be placed in si_code for a SIGBUS signal:
409
410           BUS_ADRALN
411                  Invalid address alignment.
412
413           BUS_ADRERR
414                  Nonexistent physical address.
415
416           BUS_OBJERR
417                  Object-specific hardware error.
418
419           BUS_MCEERR_AR (since Linux 2.6.32)
420                  Hardware  memory  error  consumed on a machine check; action
421                  required.
422
423           BUS_MCEERR_AO (since Linux 2.6.32)
424                  Hardware memory error detected in process but not  consumed;
425                  action optional.
426
427       The following values can be placed in si_code for a SIGTRAP signal:
428
429           TRAP_BRKPT
430                  Process breakpoint.
431
432           TRAP_TRACE
433                  Process trace trap.
434
435           TRAP_BRANCH (since Linux 2.4, IA64 only)
436                  Process taken branch trap.
437
438           TRAP_HWBKPT (since Linux 2.4, IA64 only)
439                  Hardware breakpoint/watchpoint.
440
441       The following values can be placed in si_code for a SIGCHLD signal:
442
443           CLD_EXITED
444                  Child has exited.
445
446           CLD_KILLED
447                  Child was killed.
448
449           CLD_DUMPED
450                  Child terminated abnormally.
451
452           CLD_TRAPPED
453                  Traced child has trapped.
454
455           CLD_STOPPED
456                  Child has stopped.
457
458           CLD_CONTINUED (since Linux 2.6.9)
459                  Stopped child has continued.
460
461       The  following values can be placed in si_code for a SIGIO/SIGPOLL sig‐
462       nal:
463
464           POLL_IN
465                  Data input available.
466
467           POLL_OUT
468                  Output buffers available.
469
470           POLL_MSG
471                  Input message available.
472
473           POLL_ERR
474                  I/O error.
475
476           POLL_PRI
477                  High priority input available.
478
479           POLL_HUP
480                  Device disconnected.
481
482       The following value can be placed in si_code for a SIGSYS signal:
483
484           SYS_SECCOMP (since Linux 3.5)
485                  Triggered by a seccomp(2) filter rule.
486
487   Dynamically probing for flag bit support
488       The sigaction() call on Linux accepts unknown bits set in act->sa_flags
489       without  error.  The behavior of the kernel starting with Linux 5.11 is
490       that   a   second   sigaction()   will   clear   unknown   bits    from
491       oldact->sa_flags.   However,  historically,  a  second sigaction() call
492       would typically leave those bits set in oldact->sa_flags.
493
494       This means that support for new flags  cannot  be  detected  simply  by
495       testing  for a flag in sa_flags, and a program must test that SA_UNSUP‐
496       PORTED has been cleared before relying on the contents of sa_flags.
497
498       Since the behavior of the signal handler cannot  be  guaranteed  unless
499       the  check passes, it is wise to either block the affected signal while
500       registering the handler and performing the check in this case, or where
501       this  is not possible, for example if the signal is synchronous, to is‐
502       sue the second sigaction() in the signal handler itself.
503
504       In kernels that do not support a specific flag, the  kernel's  behavior
505       is  as  if  the  flag  was  not  set,  even  if  the  flag  was  set in
506       act->sa_flags.
507
508       The   flags   SA_NOCLDSTOP,   SA_NOCLDWAIT,   SA_SIGINFO,   SA_ONSTACK,
509       SA_RESTART,  SA_NODEFER, SA_RESETHAND, and, if defined by the architec‐
510       ture, SA_RESTORER may not be reliably probed for using this  mechanism,
511       because  they  were introduced before Linux 5.11.  However, in general,
512       programs may assume that these flags are supported, since they have all
513       been supported since Linux 2.6, which was released in the year 2003.
514
515       See EXAMPLES below for a demonstration of the use of SA_UNSUPPORTED.
516

RETURN VALUE

518       sigaction()  returns  0 on success; on error, -1 is returned, and errno
519       is set to indicate the error.
520

ERRORS

522       EFAULT act or oldact points to memory which is not a valid part of  the
523              process address space.
524
525       EINVAL An invalid signal was specified.  This will also be generated if
526              an attempt is made to change the action for SIGKILL or  SIGSTOP,
527              which cannot be caught or ignored.
528

CONFORMING TO

530       POSIX.1-2001, POSIX.1-2008, SVr4.
531

NOTES

533       A child created via fork(2) inherits a copy of its parent's signal dis‐
534       positions.  During an execve(2), the dispositions  of  handled  signals
535       are  reset to the default; the dispositions of ignored signals are left
536       unchanged.
537
538       According to POSIX, the behavior of a process is undefined after it ig‐
539       nores  a  SIGFPE,  SIGILL,  or SIGSEGV signal that was not generated by
540       kill(2) or raise(3).  Integer division by zero  has  undefined  result.
541       On some architectures it will generate a SIGFPE signal.  (Also dividing
542       the most negative integer by -1 may generate  SIGFPE.)   Ignoring  this
543       signal might lead to an endless loop.
544
545       POSIX.1-1990  disallowed  setting  the  action  for SIGCHLD to SIG_IGN.
546       POSIX.1-2001 and later allow this possibility, so that ignoring SIGCHLD
547       can  be  used to prevent the creation of zombies (see wait(2)).  Never‐
548       theless, the historical BSD and System V behaviors for ignoring SIGCHLD
549       differ,  so  that  the only completely portable method of ensuring that
550       terminated children do not become zombies is to catch the SIGCHLD  sig‐
551       nal and perform a wait(2) or similar.
552
553       POSIX.1-1990 specified only SA_NOCLDSTOP.  POSIX.1-2001 added SA_NOCLD‐
554       STOP, SA_NOCLDWAIT, SA_NODEFER, SA_ONSTACK,  SA_RESETHAND,  SA_RESTART,
555       and  SA_SIGINFO.   Use  of  these latter values in sa_flags may be less
556       portable in applications intended for older UNIX implementations.
557
558       The SA_RESETHAND flag is compatible with the  SVr4  flag  of  the  same
559       name.
560
561       The  SA_NODEFER  flag is compatible with the SVr4 flag of the same name
562       under kernels 1.3.9 and later.  On older kernels the Linux  implementa‐
563       tion  allowed  the  receipt  of any signal, not just the one we are in‐
564       stalling (effectively overriding any sa_mask settings).
565
566       sigaction() can be called with a NULL second argument to query the cur‐
567       rent signal handler.  It can also be used to check whether a given sig‐
568       nal is valid for the current machine by calling it with NULL second and
569       third arguments.
570
571       It  is  not possible to block SIGKILL or SIGSTOP (by specifying them in
572       sa_mask).  Attempts to do so are silently ignored.
573
574       See sigsetops(3) for details on manipulating signal sets.
575
576       See signal-safety(7) for a list of the async-signal-safe functions that
577       can be safely called inside from inside a signal handler.
578
579   C library/kernel differences
580       The  glibc  wrapper function for sigaction() gives an error (EINVAL) on
581       attempts to change the disposition of the two  real-time  signals  used
582       internally  by  the NPTL threading implementation.  See nptl(7) for de‐
583       tails.
584
585       On architectures where the signal trampoline resides in the C  library,
586       the  glibc  wrapper  function for sigaction() places the address of the
587       trampoline code in the act.sa_restorer field and sets  the  SA_RESTORER
588       flag in the act.sa_flags field.  See sigreturn(2).
589
590       The  original  Linux  system call was named sigaction().  However, with
591       the addition of real-time signals in Linux 2.2, the fixed-size,  32-bit
592       sigset_t  type supported by that system call was no longer fit for pur‐
593       pose.  Consequently, a new system call, rt_sigaction(),  was  added  to
594       support  an enlarged sigset_t type.  The new system call takes a fourth
595       argument, size_t sigsetsize, which specifies the size in bytes  of  the
596       signal  sets  in act.sa_mask and oldact.sa_mask.  This argument is cur‐
597       rently required to have the value sizeof(sigset_t) (or the error EINVAL
598       results).   The  glibc sigaction() wrapper function hides these details
599       from us, transparently calling rt_sigaction() when the kernel  provides
600       it.
601
602   Undocumented
603       Before the introduction of SA_SIGINFO, it was also possible to get some
604       additional information about the signal.  This was done by providing an
605       sa_handler signal handler with a second argument of type struct sigcon‐
606       text, which is the same structure as the one  that  is  passed  in  the
607       uc_mcontext  field  of  the  ucontext  structure  that is passed (via a
608       pointer) in the third argument of the sa_sigaction  handler.   See  the
609       relevant Linux kernel sources for details.  This use is obsolete now.
610

BUGS

612       When delivering a signal with a SA_SIGINFO handler, the kernel does not
613       always provide meaningful values for all of the fields of the siginfo_t
614       that are relevant for that signal.
615
616       In  kernels  up  to  and  including  2.6.13,  specifying  SA_NODEFER in
617       sa_flags prevents not only the delivered signal from being masked  dur‐
618       ing  execution  of  the  handler,  but  also  the  signals specified in
619       sa_mask.  This bug was fixed in kernel 2.6.14.
620

EXAMPLES

622       See mprotect(2).
623
624   Probing for flag support
625       The following example program exits with status EXIT_SUCCESS if  SA_EX‐
626       POSE_TAGBITS is determined to be supported, and EXIT_FAILURE otherwise.
627
628       #include <signal.h>
629       #include <stdlib.h>
630       #include <stdio.h>
631       #include <unistd.h>
632
633       void
634       handler(int signo, siginfo_t *info, void *context)
635       {
636           struct sigaction oldact;
637
638           if (sigaction(SIGSEGV, NULL, &oldact) == -1 ||
639                   (oldact.sa_flags & SA_UNSUPPORTED) ||
640                   !(oldact.sa_flags & SA_EXPOSE_TAGBITS)) {
641               _exit(EXIT_FAILURE);
642           }
643           _exit(EXIT_SUCCESS);
644       }
645
646       int
647       main(void)
648       {
649           struct sigaction act = { 0 };
650
651           act.sa_flags = SA_SIGINFO | SA_UNSUPPORTED | SA_EXPOSE_TAGBITS;
652           act.sa_sigaction = &handler;
653           if (sigaction(SIGSEGV, &act, NULL) == -1) {
654               perror("sigaction");
655               exit(EXIT_FAILURE);
656           }
657
658           raise(SIGSEGV);
659       }
660

SEE ALSO

662       kill(1),  kill(2),  pause(2), pidfd_send_signal(2), restart_syscall(2),
663       seccomp(2), sigaltstack(2), signal(2), signalfd(2), sigpending(2), sig‐
664       procmask(2), sigreturn(2), sigsuspend(2), wait(2), killpg(3), raise(3),
665       siginterrupt(3), sigqueue(3), sigsetops(3),  sigvec(3),  core(5),  sig‐
666       nal(7)
667

COLOPHON

669       This  page  is  part of release 5.13 of the Linux man-pages project.  A
670       description of the project, information about reporting bugs,  and  the
671       latest     version     of     this    page,    can    be    found    at
672       https://www.kernel.org/doc/man-pages/.
673
674
675
676Linux                             2021-08-27                      SIGACTION(2)
Impressum