Skip to content

Signal -k children individually, not the process group - #3498

Closed
MRX-72 wants to merge 1 commit into
nmap:masterfrom
MRX-72:fix-ncat-process-group
Closed

MRX-72 wants to merge 1 commit into
nmap:masterfrom
MRX-72:fix-ncat-process-group

Conversation

@MRX-72

@MRX-72 MRX-72 commented Sep 17, 2026

Copy link
Copy Markdown

Ncat in listen mode forwards a termination signal with kill(0, ...), which
targets its whole process group. Ncat does not create a group of its own, so
that group is the one it inherited from whatever launched it, and the caller
is terminated as well. The handlers are installed for listeners that do not
use -k either.

Reported against the OVN system test suite, where the cleanup SIGTERM to
ncat -4 -l -u -p 1234 -d 0.1 -c cat killed the test runner and the suite
exited with status 143.

Track the PIDs that are forked for connections and signal those one by one.
Slots are released when a child is reaped, and SIGCHLD is blocked while the
signal is forwarded so that a PID cannot be recycled in the middle of it.
waitpid() with WNOHANG confirms each PID is still one of our children before
it is signalled. The children restore the default dispositions for these
signals, so that they terminate instead of forwarding the signal again.

Fixes #3489

Ncat inherits the process group of whatever launched it, so the kill(0, ...)
that forwarded a termination signal also terminated the caller: a shell
script or test harness that starts a listener was taken down with it. Track
the PIDs forked for connections and signal those instead, releasing a slot
when the child is reaped. SIGCHLD is blocked while the signal is forwarded so
that a PID cannot be recycled in the middle of it, and the children restore
the default dispositions so that they terminate rather than forward it again.
@MRX-72
MRX-72 force-pushed the fix-ncat-process-group branch from 306881d to 10fc2eb Compare September 18, 2026 16:36
@MRX-72

MRX-72 commented Sep 19, 2026 •

Copy link
Copy Markdown
Author

This has landed in master as 4d67c06 — thanks @bonsaiviking.

Noting it here since the SVN-side commit doesn't auto-close the PR, and the diff is now empty against master apart from your follow-up in 469fff8: exit() → _exit() inside the handler. Good catch, and it's the right call — exit() runs atexit handlers and flushes stdio, neither of which is async-signal-safe, so it could deadlock against an interrupted stdio lock. That exit() predates this change; I moved the call without questioning it.

Happy for this to be closed whenever suits.

@dmiller

dmiller commented Sep 19, 2026

Copy link
Copy Markdown

Your 'thanks' attributed the wrong person, in case you'd like to acknowledge the intended person.

@MRX-72 MRX-72 closed this Sep 22, 2026
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.

Ncat 7.991 propagates SIGTERM to its caller's process group

2 participants