Page MenuHomeFreeBSD

signalfd: Add native support for Linux's signalfd
Needs ReviewPublic

Authored by jfree on Jun 28 2023, 7:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Feb 13, 11:13 AM
Unknown Object (File)
Sat, Feb 7, 8:23 PM
Unknown Object (File)
Jan 22 2026, 12:11 PM
Unknown Object (File)
Jan 2 2026, 5:07 PM
Unknown Object (File)
Dec 28 2025, 7:07 PM
Unknown Object (File)
Dec 27 2025, 1:11 AM
Unknown Object (File)
Nov 27 2025, 11:27 PM
Unknown Object (File)
Nov 26 2025, 10:25 AM

Details

Summary
signalfd: Add native support for Linux's signalfd

The signalfd system call handles signals using a special signalfd file
descriptor. The caller may specify a mask of signals for signalfd to
catch. When the desciptor is read, it will return a signalfd_siginfo
structure populated with signal information from the sigqueue, similar
to sigwaitinfo(2).

The signalfd descriptor maintains traditional file descriptor semantics,
so it may be passed to other processes, preserved across fork(2), and
monitored via kevent(2), poll(2), or select(2).

This signalfd interface is based on the behavior of Linux's signalfd
implementation. It was designed to be drop-in compatible with existing
Linux signalfd code.
Test Plan

This implementation passes all of epoll-shim's signalfd tests:
https://github.com/jiixyj/epoll-shim/blob/master/test/signalfd-test.c

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

jfree requested review of this revision.Jun 28 2023, 7:52 PM

This has come up in the context of Linux-compatibility jails with musl libc distributions. Could someone please review this?

For example in context:

Feb 17 18:51:12 myhost kernel: linux: jid 7 pid 54884 (node): syscall membarrier not implemented
Feb 17 18:57:33 myhost kernel: linux: jid 8 pid 56301 (postgres): syscall signalfd4 not implemented
Feb 17 18:57:33 myhost kernel: linux: jid 8 pid 56301 (postgres): syscall signalfd not implemented

jhb added inline comments.
sys/kern/sys_signalfd.c
97

These would only be for SIGCHLD and would come from the rusage for the child process. If we wanted this, we would just need to extend ksiginfo_t to add those fields and then pass the full ksi to this function. We could also perhaps extend our native siginfo_t to pass those fields for SIGCHLD as well. We do have room in the existing union to add these fields (which would perhaps be the simplest path forward). That could be done as a separate followup even.

99

Hmm, I can't find documentation for ssi_call_addr or ssi_arch and what they are supposed to even be.

103

Does Linux only provide this for SIGBUS? On FreeBSD we provide this for various signals (the claim I wrote in siginfo(3) is that this is set for any synchronous signal). I think you could just assign this unconditionally.

sys/sys/signalfd.h
64

This should probably be a _Static_assert()