fix(libkernel): let a guest ignore or catch SIGPIPE on Linux #11002
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11002"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-25T13:58:54Z.
What
A write to a socket or pipe whose reader is gone fails with
EPIPEand raisesSIGPIPE: on FreeBSD the socket layer raises it for sockets, assoo_writedoes, anddofilewriteraises it for other files. A program that does not want a dropped connection to end it ignoresSIGPIPEor catches it. Guest signals reach the host only for 2, 4, 6, 8, 11 and 15 (NativeSignalinSignals.cpp), so a guest'ssignal(SIGPIPE, SIG_IGN)orSIGPIPEhandler was recorded but never applied. The host'sSIGPIPEkept its default action and ended the process on the first such write.docs/dev/debt/libkernel.mdlists this: "the guest cannot ignore it".One title that does this is the VLC port (PPSA85300), whose web server ignores
SIGPIPEfor "a phone closing the page mid-answer" and thenwrites to the client socket.Outside Windows, guest signal 13 is now the host's
SIGPIPE, like the other six:EPIPE;As for the other mapped signals, blocking it under the default disposition does not stop the host's default action, which ends the process. The debt entry now says that. The other debt entries that list the mapped signals now include 13: the pending-signal entry, the
sigactionentry's list of handlers that run, and thesigtimedwaitentry. That entry also says what VLC's drain after a failed write finds.GuestSignalsused 13 as its example of a signal without a host equivalent; it uses 12 now.The mapping is the smallest change to
Signals.cpp, because #9499 reworksDispatch,Installand pending delivery in the same file. This adds onecaseand one list entry there.Tested
Linux (Ubuntu 24.04, GCC 13.3), this branch rebased onto
main636a9c1eec, after #10299:guest_broken_pipe, registered outside Windows. A guest-sidewriteto a socketpair whose peer is closed:EPIPE(32);sigpendingand the handler runs when_sigprocmaskunblocks it;sigtimedwaitwith a zero timeout takes it, and the unblock then runs nothing;sigtimedwaitreturnsEAGAIN, as FreeBSD 11.4'stdsendsignaldiscards an ignored signal whatever the mask.mainthe test is killed by the host signal (SIGPIPE***Exception). With this PR it passes.guest_signals,guest_sigtimedwait,guest_signal_list,guest_signal_sets,guest_socket_pairandguest_recvmsg_memorypass.guest_*tests, run before the rebase onmaina5a780eaa: 699 pass.guest_usbddidn't run because its library needs the libusb submodule, which isn't checked out here.Overlap: #11040 adds a pipe entry right after the
read, write and vector I/Odebt entry this PR updates, so whichever lands second has a small text conflict there. That entry says a Linux guest can't ignore the hostSIGPIPE, and its author will update that clause if this PR lands first.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:10:34Z.
Review: APPROVED
Reviewed the Linux-only SIGPIPE mapping and signal lifecycle. The POSIX branch maps guest signal 13 to host SIGPIPE, includes it in dispatch lookup, and leaves Windows unchanged; the test exercises ignored, caught, and blocked-then-unblocked dispositions against a closed socket peer. I verified conventions/diff cleanliness and both changed C++ files pass local C++20 syntax checks (the Signals.cpp compile emits the pre-existing
_sigintr_nid_postfixextern-initializer warning). The reported focused and broad guest tests are strong; hosted product jobs are skipped, and the PR documents the unrunguest_usbdtest due to the absent libusb submodule.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T14:28:48Z.
Review: COMMENTED
Reviewed head
13b894b8bfe0a0e6c9bd9596f3a3ad07e6d8ef20, merged locally onto current main3a2c51afd2ee6a824cd3a294912c65e6bbf2b768(clean). WSL2 Ubuntu 24.04, GCC 13.3, Release, focused targets only.What I ran:
guest_broken_pipe,guest_signals,guest_sigtimedwait,guest_signal_list,guest_signal_sets,guest_socket_pair,guest_socket_stream_options,guest_recvmsg_memorypass.check_conventions.py --base origin/main: 0 errors.Signals.cppback to main, your test kept.guest_broken_pipedies withSIGPIPE***Exception, so the test catches it.guest_socket_optionsandguest_socket_read_writefail here on both trees with the same message, so that's my WSL loopback, not this PR.pipe()write with 13 ignored givesEPIPE; with asigactionhandler (flags 0),send(..., 0)and apipe()write each run it once;MSG_NOSIGNALandSO_NOSIGPIPEdon't; with 13 blocked under a handler,sigtimedwaitwith a zero timeout takes 13 and the unblock runs nothing; with 13 ignored and blocked nothing is pending (EAGAIN);raise(13)andkill(0, 13)with a handler run it.raise(13)under the default action now ends the process (exit 141), which is FreeBSD's default action for SIGPIPE.soo_write(sys_socket.c L147-149 at 8c639945) and 11.4dofilewrite(sys_generic.c L596-599). The pipe case matches the second one.The code looks right to me. Two debt lines on the merged tree still describe the old behaviour:
docs/dev/debt/libkernel.md:251(sigtimedwait) ends with "SIGPIPEhas no host equivalent and is never raised by a host write here (seeread, write and vector I/O), so VLC's drain finds nothing". The entry it points to now says the opposite, and the probe above shows the drain finding 13 when a handler is set. Something like: "On Linux guest 13 is the hostSIGPIPE: with a handler and 13 blocked, a failed write leaves 13 pending for VLC's drain; ignored, nothing is pending, as FreeBSD discards it. Nothing is raised on Windows, so the drain finds nothing there".docs/dev/debt/libkernel.md:254(sigaction) says only handlers on "SIGINT,SIGILL,SIGABRT,SIGFPE,SIGSEGV,SIGTERM" run.SIGPIPEoutside Windows belongs in that list now, same as you did for the pause entry.