Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rt_sigaction(2)

FieldValue
Numbers (x64 / i386 / arm64-generic / arm32)rt_sigaction: 13 / 174 / 134 / 174 (ledger SC-rt_sigaction; verified syscall_64.tbl line 25, syscall_generic.tbl line 170, syscall_arm.tbl line 191, syscall_32.tbl line 189); legacy sigaction: - / 67 / - / 67 (ledger SC-sigaction; verified syscall_32.tbl line 82)
Since (kernel)rt_sigaction 2.2 (sigaction.2: “with the addition of real-time signals in Linux 2.2 … rt_sigaction() was added”); legacy sigaction 1.0 (ledger SC-sigaction)
Man pageman2/sigaction.2 (cached); rt_sigaction.2 is an .so alias (“.so man2/sigaction.2”)
glibc wrapperglibc sigaction(3) transparently calls rt_sigaction() when the kernel provides it and hides the sigsetsize argument (sigaction.2, C library/kernel differences); returns EINVAL on attempts to change the disposition of the two NPTL-internal real-time signals (sigaction.2)
Aliases coveredrt_sigaction (kernel name), legacy sigaction (i386/arm32 slot 67, 32-bit sigset_t ABI)
Ledger IDSC-rt_sigaction, SC-sigaction

Purpose

rt_sigaction() installs or queries the disposition of one signal: what happens when that signal is delivered (default action, ignore, or a handler). It is the rt_* form of the original sigaction() syscall, added in Linux 2.2 because the fixed-size 32-bit sigset_t of the old call could not express the real-time signal range (sigaction.2, C library/kernel differences).

Synopsis

#include <signal.h>
int sigaction(int signum, const struct sigaction *act,
              struct sigaction *oldact);
/* kernel ABI */
int rt_sigaction(int signum, const struct kernel_sigaction *act,
                 struct kernel_sigaction *oldact, size_t sigsetsize);

Arguments and behavior

signum is the signal number (from <signal.h>; SIGKILL and SIGSTOP cannot be changed). If act is non-NULL the new action is installed; if oldact is non-NULL the previous action is saved; both may be NULL (sigaction.2). The struct sigaction in user space (glibc bits/sigaction.h) holds a handler union (sa_handler, or sa_sigaction with SA_SIGINFO), sa_mask (blocked during handler execution, in addition to the triggering signal unless SA_NODEFER), sa_flags, and sa_restorer (not for application use). The kernel call takes a fourth argument sigsetsize, currently required to equal sizeof(sigset_t) or EINVAL results (sigaction.2).

Return value and errors

0 on success; -1 with errno on error. Errors (sigaction.2): EFAULT (act or oldact points outside the address space); EINVAL (invalid signal, or attempt to change SIGKILL/SIGSTOP, or wrong sigsetsize on the kernel call).

Flags and constants

FlagValue (glibc bits/sigaction.h unless noted)Meaning (sigaction.2)Since
SA_NOCLDSTOP1no SIGCHLD when children stop/continue1.0
SA_NOCLDWAIT2do not create zombies on child death2.6 (man: 2.5.60 comment)
SA_SIGINFO4three-argument handler (sig, siginfo_t *, ucontext)2.2
SA_ONSTACK0x08000000run handler on sigaltstack(2) stack1.0
SA_RESTART0x10000000BSD-style restartable syscalls1.0
SA_NODEFER0x40000000do not block the signal inside its handler (alias SA_NOMASK)1.0
SA_RESETHAND0x80000000reset to SIG_DFL on handler entry (alias SA_ONESHOT)1.0
SA_INTERRUPT0x20000000historical no-op (glibc __USE_MISC only)-
SA_RESTORERnot exposed in glibc headerskernel-internal: sa_restorer holds the trampoline (see sigreturn)-
SA_UNSUPPORTEDvalue unverified (not in installed headers)probe for flag-bit support5.11
SA_EXPOSE_TAGBITSvalue unverified (not in installed headers)keep arch tag bits in si_addr5.11

Security and notes

Dispositions of handled signals reset to default across execve(); ignored dispositions persist; fork() inherits dispositions (sigaction.2 NOTES). POSIX leaves behavior undefined after ignoring SIGFPE/SIGILL/SIGSEGV not generated by kill(2)/raise(3). Attempts to block SIGKILL/SIGSTOP in sa_mask are silently ignored.

References

  • https://man7.org/linux/man-pages/man2/sigaction.2.html
  • /usr/include/x86_64-linux-gnu/bits/sigaction.h (struct and flag values)
  • worklog Task 1-e (signal-time chapter, kernel 2.2 rt_* split)