BSD syscall#46
svc · unix #46
sigaction
Installs or queries the disposition of a signal, including handler and flags.
Prototype
int sigaction(int signum, struct __sigaction *nsa, struct sigaction *osa);Returns: int
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| signum | int | - | |
| nsa | struct __sigaction | - | |
| osa | struct sigaction | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 46 |
| xnu-1486.2.11 | — | 46 |
| xnu-1504.15.3 | — | 46 |
| xnu-1504.3.12 | — | 46 |
| xnu-1504.7.4 | — | 46 |
| xnu-1504.9.17 | — | 46 |
| xnu-1504.9.26 | — | 46 |
| xnu-1504.9.37 | — | 46 |
Examples
Install SIGINT handler
#include <signal.h>
void on_int(int s) { (void)s; }
struct sigaction sa = {0};
sa.sa_handler = on_int;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGINT, &sa, NULL);Notes
The struct sigaction lets you pick SA_SIGINFO (three-argument handler with siginfo_t and ucontext_t), SA_RESTART to auto-restart interrupted syscalls, SA_ONSTACK to run on the alt stack, and SA_RESETHAND for one-shot semantics. On Darwin, the libc wrapper routes through __sigaction with the trampoline at _sigtramp, which is what unwinders rely on.
Detection
DTrace syscall::sigaction:entry shows arg0 as signal number; combine with copyinstr of handler address for symbolication. Frequently sanity-checked by sandbox profiles.
Related APIs
killsigprocmasksigaltstacksigsuspend__sigwait