Skip to content

Propagate signal exit status to parent process#156

Merged
magicant merged 1 commit into
trunkfrom
signal-exit-status
Apr 18, 2025
Merged

Propagate signal exit status to parent process#156
magicant merged 1 commit into
trunkfrom
signal-exit-status

Conversation

@magicant

Copy link
Copy Markdown
Owner

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:

  • Shell termination with signals: The shell now terminates itself with the same signal as the last command if the command's exit status indicates termination by a signal. This behavior is implemented in the exit_shell_with_status function, with a new helper function maybe_raise to handle signal propagation. (yash.c, [1] [2]

Documentation updates:

  • English documentation: Updated the doc/_exit.txt and doc/_return.txt files to explain the new behavior for exit statuses greater than 384 and clarify that such values are non-portable extensions. [1] [2] [3] [4]
  • Japanese documentation: Synchronized updates to the Japanese documentation in doc/ja/_exit.txt, doc/ja/_return.txt, and doc/ja/exec.txt to reflect the changes in exit status handling. [1] [2] [3] [4] [5]

Test suite enhancements:

  • New test cases: Added extensive test cases in tests/exit-p.tst to verify the shell's behavior when handling exit statuses greater than 256, including propagation of termination signals such as SIGTERM and SIGKILL.
  • Test configuration: Updated tests/POSIX to include references to the new test file exit-p.tst.

Codebase updates:

  • Helper function for signal handling: Introduced the maybe_raise function in yash.c to encapsulate the logic for terminating the shell with a signal, including special handling for non-fatal signals and disabling core dumps. [1] [2]
  • Header adjustments: Added necessary includes for signal handling, such as <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.

@magicant magicant added this to the 2.59 milestone Apr 17, 2025
@magicant magicant self-assigned this Apr 17, 2025
@magicant magicant mentioned this pull request Apr 17, 2025
56 tasks
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
magicant force-pushed the signal-exit-status branch from 217748c to cb35849 Compare April 17, 2025 15:48
@magicant
magicant merged commit d02a7d7 into trunk Apr 18, 2025
@magicant
magicant deleted the signal-exit-status branch April 18, 2025 02:32
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.

1 participant