Skip to content

rtapi_app: ignore SIGPIPE - #4895

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:rtapi-sigpipe
Nov 24, 2026
Merged

BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:rtapi-sigpipe

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

When the reader of rtapi_app's stderr goes away, for example halrun x.hal | grep -q pattern, the next message rtapi_app prints kills it with SIGPIPE. If the master holds the HAL mutex at that moment, every later halcmd spins on the mutex forever. Bertho hit this as a hang in tests/virtual-time of #4893 under load.

The fix ignores SIGPIPE at the start of main(), so the master and the clients get EPIPE from the write instead of dying.

New test tests/uspace/closed-stderr: no existing test runs halrun with a broken stderr. It gives halrun a stderr pipe without a reader. Before the fix halrun exits 141 and leaves the shared memory behind; with the fix the thread is created and halrun exits 0.

When the reader of rtapi_app's stderr went away, for example
halrun x.hal | grep -q pattern, the next message killed the master with
SIGPIPE. If it held the HAL mutex at that moment, every later halcmd
spun on the mutex forever. Bertho Stultiens hit this as a hang in the
tests/virtual-time test of LinuxCNC#4893 under load.

Ignore SIGPIPE at the start of main(), so the master and every client
get EPIPE from the write instead.

tests/uspace/closed-stderr runs halrun with a stderr pipe that has no
reader: before the fix halrun exits 141 and leaves the shared memory
behind, with it the thread is created and halrun exits 0.
@BsAtHome

Copy link
Copy Markdown
Contributor

Yeah, I was worried it was a signal issue. The hang no longer happens with the SIGPIPE signal ignored. Shouldn't SIGHUP also be ignored (when someone kills the vt)?

@grandixximo

Copy link
Copy Markdown
Contributor Author

Thanks for checking. I don't think SIGHUP needs it: the master calls setsid() in start_master(), so it runs in its own session without a controlling terminal, and the kernel never sends it a hangup when the vt goes away. Writes to the dead terminal then return EIO, no signal. I checked under a pty: the master has its own SID and no tty. The rtapi_app clients do get SIGHUP, but they only wait on the socket and hold no HAL mutex; the master's reply to a dead client now gets EPIPE instead of killing it.

@BsAtHome

Copy link
Copy Markdown
Contributor

Right then, thanks for checking.

@BsAtHome
BsAtHome merged commit df13431 into LinuxCNC:master Nov 24, 2026
18 of 19 checks passed
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.

2 participants