Skip to content

socket: add MSG_NOSIGNAL for Apple targets - #2828

Open
mbgrydeland wants to merge 3 commits into
nix-rust:masterfrom
mbgrydeland:msg-nosignal-apple
Open

mbgrydeland wants to merge 3 commits into
nix-rust:masterfrom
mbgrydeland:msg-nosignal-apple

Conversation

@mbgrydeland

@mbgrydeland mbgrydeland commented Sep 23, 2026 •

Copy link
Copy Markdown

XNU has honoured MSG_NOSIGNAL on send since it adopted the POSIX.1-2008 flag, and libc defines it for Apple targets.

What does this PR do

Adds MSG_NOSIGNAL as a valid bit flag on struct MsgFlags on apple_targets.

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

@2570165831

Copy link
Copy Markdown

I tested this on real hardware, in case it helps review.

macOS 27.2, arm64. A small C program closes the peer, then calls send() in a child with SIGPIPE at its default disposition:

socket flags result
AF_UNIX stream pair none child killed by SIGPIPE
AF_UNIX stream pair MSG_NOSIGNAL send returns EPIPE, no signal
TCP over loopback none child killed by SIGPIPE
TCP over loopback MSG_NOSIGNAL send returns EPIPE, no signal

So the flag is honoured there, and the value matches libc (0x80000).

On "since when": in the published XNU sources the flag first appears in xnu-7195 (macOS 11 / iOS 14), both in bsd/sys/socket.h and in the SIGPIPE check in bsd/kern/uipc_syscalls.c. It is absent from xnu-6153 (macOS 10.15). I only read the sources for that; I have not run anything on a system older than 27. It may be worth a line in the doc comment, since x86_64-apple-darwin binaries can still target older systems, where an unknown flag bit would presumably be ignored and the signal still raised.

Happy to share the test program if useful.

@xtqqczze

This comment was marked as resolved.

@mbgrydeland

Copy link
Copy Markdown
Author

Force-pushed rebase on master

@xtqqczze

This comment was marked as resolved.

Comment thread src/sys/socket/mod.rs
@xtqqczze

This comment was marked as resolved.

XNU has honoured MSG_NOSIGNAL on send since it adopted the POSIX.1-2008
flag, and libc defines it for Apple targets.
@mbgrydeland

Copy link
Copy Markdown
Author

Force pushed rebase on master

With apple_targets added, the freebsdlike, netbsdlike and apple_targets
aliases together cover exactly the platforms in the bsd alias, so use
that instead.
@mbgrydeland

Copy link
Copy Markdown
Author

Had to trigger a rerun to get past an apparent flaky test, that as far as I can see is not related to the changes from this PR. CI is all green now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants