Propagate signal exit status to parent process#156
Merged
Conversation
POSIX.1-2024 updated the requirements on the exit built-in. We now examine the exit status of the last command and if it is a signal number we propagate the signal to the shell process.
magicant
force-pushed
the
signal-exit-status
branch
from
April 17, 2025 15:48
217748c to
cb35849
Compare
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.
POSIX.1-2024 updated the requirements on the exit built-in. We now examine the exit status of the last command and if it is a signal number we propagate the signal to the shell process.
See magicant/yash-rs#491 for the yash-rs equivalent.
Summary by Copilot
This pull request introduces a significant change to how the shell handles exit statuses when commands are terminated by signals. It ensures that the shell propagates the termination signal of the last command by terminating itself with the same signal. Additionally, it updates documentation and tests to reflect this behavior and introduces a new helper function in the codebase.
Changes to exit status handling:
exit_shell_with_statusfunction, with a new helper functionmaybe_raiseto handle signal propagation. (yash.c, [1] [2]Documentation updates:
doc/_exit.txtanddoc/_return.txtfiles to explain the new behavior for exit statuses greater than 384 and clarify that such values are non-portable extensions. [1] [2] [3] [4]doc/ja/_exit.txt,doc/ja/_return.txt, anddoc/ja/exec.txtto reflect the changes in exit status handling. [1] [2] [3] [4] [5]Test suite enhancements:
tests/exit-p.tstto verify the shell's behavior when handling exit statuses greater than 256, including propagation of termination signals such asSIGTERMandSIGKILL.tests/POSIXto include references to the new test fileexit-p.tst.Codebase updates:
maybe_raisefunction inyash.cto encapsulate the logic for terminating the shell with a signal, including special handling for non-fatal signals and disabling core dumps. [1] [2]<signal.h>and<sys/resource.h>.These changes improve the shell's compliance with signal propagation expectations and enhance its robustness in handling termination scenarios.