Signal Trapped
ID |
go.signal_trapped |
Severity |
low |
Remediation Complexity |
simple |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Best Practice |
Language |
Go |
Tags |
best-practice, portability |
Description
Reports a signal.Notify(ch, SIG…) call that traps a unix-only signal (such as
syscall.SIGUSR1 or SIGWINCH) from a source file that carries no platform build constraint.
Rationale
Signals like SIGUSR1, SIGWINCH or SIGHUP are not defined or never delivered on every
target platform — on Windows in particular. A single, unconstrained source file that relies on
such a signal behaves differently, or fails to build, when cross-compiled. Platform-specific
signal handling belongs in a file gated by a build constraint (//go:build unix) or a platform
filename suffix (_linux.go, _unix.go). Portable signals such as os.Interrupt,
syscall.SIGINT and syscall.SIGTERM are unaffected. The set of unix-only signal names is
configurable through the unixOnlySignals property.
signal.Notify(ch, syscall.SIGUSR1) // FLAW — unix-only signal, no build constraint
signal.Notify(ch, os.Interrupt) // OK — portable signal