Skip to content

Ignore remaining commands after a foreground job stops#143

Merged
magicant merged 1 commit into
trunkfrom
suspend
Mar 25, 2025
Merged

Ignore remaining commands after a foreground job stops#143
magicant merged 1 commit into
trunkfrom
suspend

Conversation

@magicant

@magicant magicant commented Mar 24, 2025

Copy link
Copy Markdown
Owner

This pull request introduces several changes to improve the handling of suspended jobs in the interactive shell and updates the documentation accordingly. The most important changes include adding new exception handling for suspended jobs, updating documentation for job control, and modifying tests to cover the new behavior.

Improvements to job suspension handling:

  • exec.c: Added new exception E_SUSPEND and functions raise_suspend and cancel_suspend to handle suspended jobs in the interactive shell. [1] [2]
  • exec.h: Updated header to include declarations for raise_suspend and cancel_suspend.
  • job.c: Modified wait_for_job and wait_for_child functions to raise E_SUSPEND exception when a job is stopped in an interactive shell. [1] [2] [3]
  • yash.c: Added a call to cancel_suspend in the parse_and_exec function to clear the suspend flag when returning to the command prompt.

Documentation updates:

  • doc/job.txt and doc/ja/job.txt: Updated job control documentation to describe the new behavior of discarding remaining commands when a job is suspended in an interactive shell. [1] [2]

Tests:

  • tests/job-y.tst: Added a test case to verify that remaining commands are discarded when a command suspends in an interactive shell.

Miscellaneous:

  • NEWS and NEWS.ja: Updated release notes to include the new behavior for handling suspended jobs in the interactive shell. [1] [2]
  • License years updated to 2025 in exec.h and yash.c. [1] [2]

@magicant magicant self-assigned this Mar 24, 2025
@magicant magicant linked an issue Mar 24, 2025 that may be closed by this pull request
POSIX.1-2024 requires that when a foreground job stops in an
interactive, job-control shell, the shell discards any remaining
commands that were typed but not yet executed, up to and including a
next asynchronous list. This is to prevent the user from accidentally
executing commands that were intended to be executed after previous
commands have completed.

Yash did not previously implement this behavior. This commit implements
the behavior, but not exactly as specified in POSIX.1-2024. Instead of
discarding commands up to and including the next asynchronous list, yash
discards all commands that were read but not executed. This is to keep
the implementation simple and should be more intuitive for users. See
<magicant/yash-rs#478> for more discussion.

To implement this behavior, the shell raises an exception when a
foreground job stops. The exception is cleared when the shell reads a
new command.
@magicant
magicant marked this pull request as ready for review March 25, 2025 15:36
@magicant magicant added this to the 2.59 milestone Mar 25, 2025
@magicant
magicant merged commit 8732f7f into trunk Mar 25, 2025
@magicant
magicant deleted the suspend branch March 25, 2025 16:03
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.

Ignore remaining commands after a foreground job stops

1 participant