Repository navigation
sched/task: Give the child of fork() the signal actions of the parent. - #21095
Merged
Merged
Conversation
The child of fork() and vfork() started with no signal actions: the action list of its new task group was empty, and so was the set of the signals that have the default action, which only nxtask_start() fills. So no signal had its default action in the child. A child that had not called exec ignored SIGTERM, SIGINT and even SIGKILL, and a handler of the parent did not run in the child. A shell forks for a subshell, for a pipeline and for a command in the background, so these could not be stopped with kill. POSIX says that the child has the signal actions of the parent, the signal mask of the calling thread (nxtask_setup_scheduler() copies it already) and no pending signals. Add nxsig_dupactions(), which copies the action list and the set of the signals with the default action to the new group, and call it in nxtask_setup_fork(). Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
requested review from
GUIDINGLI,
anchao,
jerpelea,
masayuki2009,
pussuw,
xiaoxiang781216 and
yf13
as code owners
October 28, 2026 20:43
|
acassis
approved these changes
Oct 28, 2026
xiaoxiang781216
approved these changes
Oct 29, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The child of
fork()andvfork()started with no signal actions. The action list of its new task group was empty, and so was the set of the signals that have the default action (onlynxtask_start()fills it). So no signal had its default action in the child: a child that had not called exec ignored SIGTERM, SIGINT and even SIGKILL, and a handler of the parent did not run in the child. A shell forks for a subshell, for a pipeline and for a command in the background, sokillcould not stop these.POSIX says that the child has the signal actions of the parent, the signal mask of the calling thread and no pending signals. This PR adds
nxsig_dupactions(), which copies the action list and the set of the signals with the default action to the new group, and calls it innxtask_setup_fork(). The signal mask is already copied bynxtask_setup_scheduler().Impact
All build modes and architectures with
fork()orvfork()(CONFIG_ARCH_HAVE_FORK) andCONFIG_ENABLE_ALL_SIGNALS. A child that calls exec gets the actions that exec sets, as before. No interface or structure changes.Testing
Tested on master aeab6fb and on this PR rebased on it.
Test program
forksig.conqemu-armv8a:knsh(QEMU with HVF,CONFIG_SCHED_CHILD_STATUS=y). A child that does not end sleeps 5 s and exits with 99.forkkill.c:waitpid()of a fork() child that SIGTERM endsqemu-armv8a:knshandqemu-armv8a:nshforkkill.calso checksWTERMSIG()of the status: that part needs the exit status fix for a child ended by a signal, which is not in this PR.The flat build has only
vfork(), where the parent waits for the child; there ostest (with itsvfork()test) is the check.Build, each OK:
qemu-armv8a:nsh(flat, arm64),qemu-armv8a:knsh(kernel, arm64),lm3s6965-ek:qemu-protected(protected, armv7-m),qemu-armv7a:knsh(kernel, armv7-a),rv-virt:pnsh64(protected, rv64),rv-virt:knsh64(kernel, rv64).tools/checkpatch.sh -c -u -m -gpasses.