Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to our own Signal type #367

Merged
merged 37 commits into from
Jun 8, 2024
Merged

Migrate to our own Signal type #367

merged 37 commits into from
Jun 8, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented May 25, 2024

This is part of #353, and rework of #365.

This PR removes the use of nix::signal::Signal in the yash_env::System API. The definition of Signal is dependent on the underlying system, so it should not be used outside RealSystem. Instead, new neutral items are added in the yash_env::signal module.

The new Number type replaces the most use of Signal. The RealSystem and VirtualSystem now have different Number spaces so that the VirtualSystem no longer has to depend on the RealSystem's signal number. The other uses of Signals are replaced by Names, which is more abstract than Numbers.

This PR also adds (partial) support for real-time signals.

To fully support real-time signals, we also need to eliminate the use of SigSet, which is not the scope of this pull request.


  • Defining new items
    • Define new signal items (Number and Name)
    • Implement From<Number> for ExitStatus
    • Implement System::signal_number_from_name and System::validate_signal_number
    • Implement SystemEx:signal_name_from_number
    • Implement SystemEx:signal_number_from_exit_status
    • Implement new job state reporting which depends on System and will replace yash_env::job::fmt
  • Updating existing items
    • Use Number in virtual Process
    • Let ProcessResult contain Number and update the implementation of From<ProcessResult> for ExitStatus, etc.
      • This change requires first removing the old yash::job::fmt, which depends on the old ProcessResult definition.
    • Let yash_env::trap::Condition contain Number and update dependent implementations accordingly
    • Change the signature of System::sigaction
    • Change the signature of System::caught_signals
    • Change the signature of System::kill
    • Change the signature of SelectSystem::set_signal_handling
    • Change the signature of SharedSystem::wait_for_signals
    • Change the signature of SharedSystem::wait_for_signal
  • Updating built-ins
    • Update the fg built-in implementation
    • Update the kill built-in implementation
    • Update the set built-in test
    • Update the trap built-in implementation
    • Update the wait built-in implementation
    • Update the jobs built-in implementation
  • Removing old items
    • Remove the old yash::job::fmt items
    • Remove ProcessState::from_wait_status by inlining the function
    • Remove impl TryFrom<Signal> for signal::Number
    • Remove impl From<Signal> for ExitStatus
    • Remove the old signal items
  • Refactoring
    • Split yash_builtin::trap::Command::execute into smaller functions

Summary by CodeRabbit

  • New Features

    • Added support for real-time signals in the kill built-in.
    • Introduced new entities for improved signal handling and job control.
  • Improvements

    • Enhanced signal parsing and handling logic for better maintainability and clarity.
    • Updated signal-related functions to use more precise data types and error handling.
  • Bug Fixes

    • Corrected various function signatures and return types to improve consistency and error reporting.
  • Documentation

    • Updated documentation to reflect changes in signal handling and job control mechanisms.

@magicant magicant self-assigned this May 25, 2024
Copy link

coderabbitai bot commented May 25, 2024

Walkthrough

The changes in the yash-builtin and yash-env modules primarily focus on enhancing signal handling. This involves adding new signal-related functionalities, refactoring existing signal logic, and updating function signatures and structures to accommodate these improvements. Key updates include new methods for signal validation, mapping, and handling, along with modifications to job control, trap, kill, and wait mechanisms to use these new signal handling capabilities.

Changes

File(s) Change Summary
yash-builtin/CHANGELOG.md Summarized changes in version 0.2.0, highlighting additions, modifications, and removals.
yash-builtin/src/bg.rs, fg.rs Updated signal handling logic, replacing direct signal usage with signal names.
yash-builtin/src/jobs.rs Modified job control mechanisms, renamed fields, and updated method signatures.
yash-builtin/src/kill.rs, print.rs, send.rs, signal.rs, syntax.rs Refactored signal handling, parsing, and execution logic, introduced new structures and methods.
yash-builtin/src/set.rs Updated signal references to use new modules and structures.
yash-builtin/src/trap.rs, cond.rs, syntax.rs Enhanced trap handling with new condition specifications and error handling improvements.
yash-builtin/src/wait/core.rs Adjusted error handling and signal references in wait mechanisms.
yash-env/src/system.rs Introduced new methods for signal validation, mapping, and handling, modified existing methods.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant yash-builtin
    participant yash-env

    User->>yash-builtin: Send signal via kill command
    yash-builtin->>yash-env: Validate and parse signal
    yash-env-->>yash-builtin: Return signal number
    yash-builtin->>yash-env: Execute signal handling
    yash-env-->>yash-builtin: Signal action performed
    yash-builtin-->>User: Confirmation of signal execution
Loading

Poem

In the code where signals play,
A rabbit hops through night and day.
With traps and kills, it deftly weaves,
Ensuring all the bugs it leaves.
Signals parsed with utmost care,
In yash, a system rare.
Hooray for changes, hip and bright,
The rabbit's code, a shining light! 🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@magicant magicant mentioned this pull request May 25, 2024
17 tasks
This commit modifies the type of the `signal_handlings` field of
`Process` from `HashMap<Signal, SignalHandling>` to
`HashMap<signal::Number, SignalHandling>`. This change is necessary
because the `Signal` type is being deprecated in favor of
`signal::Number`.

This commit also modifies the `signal_handling` and
`set_signal_handling` methods of `Process` to operate on
`signal::Number` instead of `Signal`.
This commit reduces the use of Signal in the virtual system by storing
signal::Number in Process::caught_signals. This is a step towards
removing Signal from the virtual system.
This commit changes the deliver_signal method to take a signal::Number
instead of a Signal. This is a step towards removing the Signal enum
from the virtual process implementation.
This commit changes the signature of Process::raise_signal to take a
signal::Number instead of a Signal. This is part of the ongoing work to
separate the signal names, real numbers, and virtual numbers.
Before adding a new Report type, rename the existing one to OldReport.
This commit changes the associated value of
`job::ProcessResult::{Stopped, Signaled}` from `trap::Signal` to
`signal::Number`. This change is part of the major restructuring to
remove the dependency on the `nix` crate in the virtual system.
Before adding a new Condition type, rename the existing one to a
different name.
Returning a tuple of error-describing values was not ergonomic. This
commit redefines the Error type as a struct with named fields. This
change also makes the Error type public so that it can be used in other
modules.
This commit adds two methods to `SignalSystem` to convert between signal
names and numbers. These methods will be needed by `TrapSet` to operate
on some specific signals such as `SIGINT` and `SIGTERM`.
This commit migrates the signal-representing type in `TrapSet` from
`Signal` to `signal::Number`. All methods of `TrapSet` that previously
took `Signal` now take `signal::Number`. Other functions are updated to
use `signal::Name` and `signal::Number` instead of `Signal`.
This is part of the effort to replace trap::Signal with signal::Number
in the System API.
This change replaces the `Signal` type with the `signal::Number` type
for the `System::sigaction` method. This change is part of the ongoing
work to remove the `Signal` type from the public API.
This commit changes the parameter and return types of functions that
deal with signals in yash-env from trap::Signal to signal::Number.
This is part of the ongoing refactoring to remove the Signal type from
the public API.
This is part of the ongoing reconstruction to eliminate the use of nix
types in the built-ins. This commit introduces the new signal types that
are now used in the kill built-in. The `Signal` type represents a signal
to be sent or printed by the kill built-in. The validity of the signal
name or number is now checked at the time of execution by the system.
This type was used to represent signals in the trap module, but it has
been replaced by yash_env::signal::Signal. This commit removes the old
type.

This commit is the final step in the extensive restructuring to remove
the nix-based Signal type from the public API of the yash_env crate.
Note that internal uses of the type still remain in the implementation,
which we plan to address later.
@magicant magicant marked this pull request as ready for review June 8, 2024 02:21
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Outside diff range and nitpick comments (3)
yash-semantics/CHANGELOG.md (1)

Line range hint 17-19: Adjust the indentation of the unordered list to match the expected level.

-    - `ValueState` was renamed to `Vacancy`.
-    - `EmptyError` was renamed to `VacantError`.
-    - `EmptyError::state` was renamed to `VacantError::vacancy`.
+  - `ValueState` was renamed to `Vacancy`.
+  - `EmptyError` was renamed to `VacantError`.
+  - `EmptyError::state` was renamed to `VacantError::vacancy`.
yash-builtin/src/trap.rs (1)

Line range hint 168-181: Refactored display_traps to utilize CondSpec.

This refactoring simplifies the display logic by leveraging the new CondSpec structure, which should make future modifications or extensions easier.

yash-env/src/trap/state.rs (1)

Line range hint 391-613: The tests are well-structured and cover various scenarios for signal handling. However, consider adding more edge cases, especially for error conditions and signal interactions.

Would you like me to help in writing additional test cases to cover more scenarios?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81e765f and 7c8518d.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (42)
  • yash-builtin/CHANGELOG.md (1 hunks)
  • yash-builtin/src/bg.rs (14 hunks)
  • yash-builtin/src/fg.rs (16 hunks)
  • yash-builtin/src/jobs.rs (19 hunks)
  • yash-builtin/src/kill.rs (2 hunks)
  • yash-builtin/src/kill/print.rs (1 hunks)
  • yash-builtin/src/kill/send.rs (6 hunks)
  • yash-builtin/src/kill/signal.rs (1 hunks)
  • yash-builtin/src/kill/syntax.rs (24 hunks)
  • yash-builtin/src/set.rs (1 hunks)
  • yash-builtin/src/trap.rs (13 hunks)
  • yash-builtin/src/trap/cond.rs (1 hunks)
  • yash-builtin/src/trap/syntax.rs (13 hunks)
  • yash-builtin/src/wait/core.rs (6 hunks)
  • yash-builtin/src/wait/status.rs (4 hunks)
  • yash-cli/src/lib.rs (2 hunks)
  • yash-env/CHANGELOG.md (2 hunks)
  • yash-env/Cargo.toml (1 hunks)
  • yash-env/src/job.rs (23 hunks)
  • yash-env/src/job/fmt.rs (2 hunks)
  • yash-env/src/lib.rs (11 hunks)
  • yash-env/src/semantics.rs (3 hunks)
  • yash-env/src/signal.rs (1 hunks)
  • yash-env/src/subshell.rs (4 hunks)
  • yash-env/src/system.rs (23 hunks)
  • yash-env/src/system/real.rs (9 hunks)
  • yash-env/src/system/real/signal.rs (1 hunks)
  • yash-env/src/system/virtual.rs (25 hunks)
  • yash-env/src/system/virtual/process.rs (23 hunks)
  • yash-env/src/system/virtual/signal.rs (2 hunks)
  • yash-env/src/trap.rs (65 hunks)
  • yash-env/src/trap/cond.rs (1 hunks)
  • yash-env/src/trap/state.rs (20 hunks)
  • yash-semantics/CHANGELOG.md (1 hunks)
  • yash-semantics/src/command.rs (3 hunks)
  • yash-semantics/src/command/compound_command/subshell.rs (2 hunks)
  • yash-semantics/src/command/item.rs (1 hunks)
  • yash-semantics/src/command/pipeline.rs (2 hunks)
  • yash-semantics/src/runner.rs (3 hunks)
  • yash-semantics/src/tests.rs (2 hunks)
  • yash-semantics/src/trap.rs (1 hunks)
  • yash-semantics/src/trap/signal.rs (16 hunks)
Files not summarized due to errors (1)
  • yash-env/src/trap.rs: Error: Message exceeds token limit
Files skipped from review due to trivial changes (2)
  • yash-builtin/src/wait/status.rs
  • yash-env/Cargo.toml
Additional context used
Markdownlint
yash-semantics/CHANGELOG.md

17-17: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


18-18: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


19-19: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

yash-env/CHANGELOG.md

40-40: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


41-41: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


42-42: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


43-43: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


44-44: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


45-45: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


46-46: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


47-47: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


48-48: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


49-49: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


50-50: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

Additional comments not posted (166)
yash-builtin/CHANGELOG.md (3)

8-20: The changelog entries for version 0.2.0 are well-documented and clearly outline the additions and changes made to the yash-builtin module.


21-43: The changes section provides a detailed account of the modifications in function signatures and behavior, which is crucial for understanding the impact of these changes on the system.


44-47: The removal of redundant functions such as kill::syntax::parse_signal_name and kill::syntax::parse_signal_name_or_number is a positive step towards simplifying the codebase.

yash-semantics/CHANGELOG.md (1)

30-31: The update to trap::run_trap_if_caught to use yash_env::signal::Number instead of yash_env::trap::Signal aligns with the overall goal of the PR to standardize signal handling.

yash-env/src/trap/cond.rs (4)

21-23: The imports are correctly updated to reflect the new dependencies and architectural changes.


32-32: The introduction of Signal(signal::Number) in the Condition enum is a key change that supports the new signal handling strategy.


35-50: The implementation of conversions from signal::Number and signal::RawNumber to Condition is well-executed, ensuring that signal numbers are correctly mapped to conditions.


55-77: The conversion of Condition to signal::RawNumber and the method to convert Condition to a string are correctly implemented, enhancing the modularity and reusability of the code.

yash-env/CHANGELOG.md (1)

14-29: The addition of new methods and types related to signal handling in the System and SystemEx interfaces is well-documented and aligns with the PR's objectives to enhance signal management.

yash-builtin/src/trap/cond.rs (6)

26-33: Introduced CondSpec enum to abstract trap conditions.

This change aligns with the PR's goal to abstract signal handling, enhancing maintainability and clarity.


35-45: Implementations of From for signal::Name and signal::RawNumber are correctly defined.

These implementations facilitate easy conversion from signal types to CondSpec, simplifying client code.


47-59: The resolve method correctly translates CondSpec to Condition.

This method ensures that the abstracted conditions can be converted back to concrete signal numbers when needed, which is crucial for integrating with existing APIs that expect Condition.


61-75: The to_condition method provides robust handling of signal names and numbers.

This method is essential for ensuring that the system can handle both named and numbered signals, which is a key part of the abstraction introduced in this PR.


77-89: The from_condition method allows reverse conversion from Condition to CondSpec.

This functionality is important for scenarios where the system needs to interpret existing conditions in terms of the new abstraction.


92-99: Implemented Display for CondSpec for better debuggability and logging.

Proper implementation of the Display trait is crucial for logging and debugging purposes, making the system's internal state more transparent.

yash-semantics/src/trap.rs (1)

80-80: Updated the run_trap function to use the new signal handling system.

This update ensures that the run_trap function aligns with the new signal handling mechanisms introduced in the PR, maintaining consistency across the codebase.

yash-semantics/src/command.rs (1)

Line range hint 95-120: Updated test cases to use the new virtual signal system.

The updates to the test cases ensure that they are compatible with the new signal handling system, which is crucial for maintaining the reliability of the command execution logic.

yash-cli/src/lib.rs (1)

137-141: Correctly implemented signal handling setup for SIGPIPE.

This setup is crucial for ensuring that the shell behaves correctly in environments where SIGPIPE needs to be handled explicitly.

yash-builtin/src/kill.rs (4)

156-158: The new signal module is correctly imported and used.


167-169: The Send command now includes a signal_origin field to track the source of the signal, enhancing traceability.


175-178: The Print command now handles a list of signals along with their origins, which is a significant improvement for debugging and logging.


192-197: The execution logic for the Send and Print commands has been updated to accommodate the new signal handling structure. This change aligns with the PR's objectives to improve signal handling.

yash-builtin/src/kill/print.rs (6)

24-33: Imports and module usage have been updated to reflect the new signal handling structure. This is necessary for the new functionality introduced in the PR.


39-62: The all_signals function now correctly iterates over both non-real-time and real-time signals, providing a comprehensive listing. This change supports the enhanced signal handling capabilities introduced in the PR.


64-72: The write_one_signal function has been adapted to handle verbose output, which is crucial for detailed debugging and logging.


74-98: The InvalidSignal struct provides a structured way to handle errors related to unrecognized signals, which is a robust enhancement for error handling.


100-131: The print function's logic has been significantly refactored to handle both all signals and specified signals, with error handling for invalid signals. This is a critical update for robustness and functionality.


136-140: The execute function now properly handles the results from the print function, ensuring that errors are reported and successes are outputted correctly.

yash-builtin/src/wait/core.rs (5)

25-25: The import of the signal module aligns with the PR's goal to enhance signal handling across the system.


39-40: The Error enum has been updated to include a new variant for trapped signals, improving error specificity and handling.


109-109: The use of SIGSTOP and SIGTERM from the virtual module is a direct consequence of the PR's changes, ensuring consistency in signal references throughout the codebase.


155-161: The handling of the SIGSTOP signal in the wait_for_any_job_or_trap function is correctly implemented, reflecting the updated signal handling strategy.


Line range hint 181-198: The handling of the SIGTERM trap in the test setup is well-implemented, demonstrating the system's ability to handle specific signals as traps.

yash-env/src/job/fmt.rs (5)

24-44: The documentation and example usage of the Report struct have been updated to reflect the new job formatting capabilities. This is crucial for clarity and usability.


49-55: The imports have been updated to include the new signal module, which is necessary for the updated job state representation.


88-133: The State enum has been significantly refactored to use signal::Name instead of signal::Number, aligning with the PR's objectives to improve signal representation in job reports.


135-157: The from_process_state function now converts ProcessState to the new State format using signal names, which is a critical update for consistency and clarity in job reporting.


160-193: The Report struct and its Display implementation have been updated to handle the new job state representation, ensuring that job reports are accurate and informative.

yash-builtin/src/kill/send.rs (5)

23-23: Updated imports to reflect the new signal handling architecture.

Also applies to: 32-32, 34-34


85-89: Refactored send function to use the new signal::Number type instead of the previous Signal type.


95-101: Introduced UnsupportedSignal error type to handle unsupported signals more explicitly.


139-157: Updated execute function to handle the new Signal type and added error handling for unsupported signals.


176-176: Added unit tests to verify the behavior of the new signal handling logic.

Also applies to: 178-178, 179-179, 182-182, 183-183

yash-builtin/src/kill/signal.rs (5)

29-36: Defined new Signal enum to represent signals by name or raw number, aligning with the new signal handling strategy.


44-57: Implemented FromStr for Signal to parse signals from strings, supporting both names and numbers.


76-98: Implemented to_number method in Signal to convert signals to their numeric representation, handling unsupported signals.


100-116: Added to_name_and_number method to Signal for retrieving both signal name and number, useful for display and logging purposes.


127-158: Enhanced unit tests to cover new functionality in Signal, including parsing and conversion between names and numbers.

Also applies to: 160-188

yash-semantics/src/command/compound_command/subshell.rs (2)

91-91: Updated imports to reflect changes in signal handling and system virtualization.

Also applies to: 92-92


196-208: Enhanced job control for suspended subshells, ensuring proper state management and job list updates.

yash-env/src/semantics.rs (4)

19-19: Updated imports to align with the new signal handling architecture.

Also applies to: 21-21


104-114: Implemented conversion from signal::Number to ExitStatus, adhering to POSIX requirements.


116-130: Implemented reverse conversion from ExitStatus to signal::Number, providing comprehensive signal handling.


257-280: Added unit tests to verify the correct conversion between ExitStatus and signal::Number.

yash-builtin/src/trap/syntax.rs (2)

131-133: The import of CondSpec and Name from yash_env::signal aligns with the PR's objective to replace old signal types with new abstract types. This change supports the new signal handling strategy.


148-148: The tests have been updated to use the new CondSpec for signal names and numbers, which is consistent with the changes in the main codebase. This ensures that the unit tests reflect the new signal handling logic.

Also applies to: 160-160, 172-172, 185-187, 200-200, 209-209, 221-221, 233-233, 245-245, 257-257, 269-269, 281-281, 293-293

yash-semantics/src/tests.rs (1)

41-41: The addition of SIGSTOP from yash_env::system::r#virtual is consistent with the PR's goal to use more abstract signal representations. This change ensures that the tests are aligned with the new signal handling strategy.

yash-semantics/src/trap/signal.rs (3)

23-23: The import of the signal module is necessary due to the refactoring of signal handling in the system, replacing old signal types with new abstract types.


41-41: The function run_trap_if_caught now uses the new signal::Number type, which is part of the PR's changes to unify signal handling. This is a crucial update for maintaining consistency across the codebase.


111-113: The tests have been updated to reflect the new signal handling logic, using signal::Number and the new Action configurations. This ensures that the unit tests are aligned with the main codebase changes.
[APROVED]

Also applies to: 124-124, 133-133, 156-156, 167-168, 179-179, 191-192, 208-208, 219-219, 225-225, 235-235, 245-245, 257-258, 274-274, 280-280, 296-296, 302-302

yash-semantics/src/command/item.rs (1)

284-291: The function ignore_sigttin correctly uses the new signal handling system to set the action for the Ttin signal. This is part of the broader refactoring effort to use more abstract signal representations.

yash-semantics/src/runner.rs (2)

Line range hint 308-319: Ensure proper signal handling in tests.

The addition of signal handling in the test running_traps_between_parsing_and_executing is a good practice for ensuring that the shell behaves correctly when signals are raised. This change aligns with the PR's objective of enhancing signal handling.


Line range hint 308-319: Verify the correct signal is raised in tests.

Verification successful

The test function running_traps_between_parsing_and_executing correctly raises the SIGUSR1 signal as expected. The signal is set and then raised within the function, and the subsequent assertions check the expected behavior.

  • The signal SIGUSR1 is set with an action to execute the command echo USR1.
  • The signal SIGUSR1 is then raised.
  • The test verifies the output and exit status.

This confirms that the correct signal is raised in the test.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the correct signal is raised in the test `running_traps_between_parsing_and_executing`.

# Test: Search for the test implementation. Expect: Only occurrences of the correct signal.
rg --type rust $'running_traps_between_parsing_and_executing'

Length of output: 144



Script:

#!/bin/bash
# Extract the content of the `running_traps_between_parsing_and_executing` function from `yash-semantics/src/runner.rs`.
ast-grep --lang rust --pattern $'fn running_traps_between_parsing_and_executing() {
  $$$
}' yash-semantics/src/runner.rs

Length of output: 2063

yash-builtin/src/set.rs (1)

262-262: Ensure proper signal handling in the set built-in.

The addition of SIGTSTP handling in the set built-in is crucial for managing job control signals appropriately. This change is consistent with the PR's goals of improving signal handling.

yash-env/src/system/real/signal.rs (1)

27-399: Comprehensive update to signal handling.

The extensive updates to signal handling in yash-env/src/system/real/signal.rs are well-implemented. The use of conditional compilation to handle platform-specific signals and the introduction of real-time signal handling are in line with modern POSIX standards and enhance the robustness of the shell.

yash-builtin/src/bg.rs (5)

97-97: Updated import to use the new yash_env::signal module.

This change aligns with the PR's objective to migrate to a custom signal type, enhancing portability and control over signal handling.


165-165: Refactored signal handling to use the new signal::Name enum and signal_number_from_name method.

This change is crucial for abstracting system-dependent signal values, which is a key goal of this PR. It also adds error handling for the case where the signal number is invalid.

Also applies to: 171-173


239-239: Import statements for SIGSTOP, SIGTSTP, and SIGTTIN have been updated to reflect their new locations.

This change is necessary due to the restructuring of signal definitions within the yash_env module, ensuring that the bg built-in uses the correct signal constants.


258-260: The test resume_job_by_index_sends_sigcont has been updated to use the new signal constants.

Properly updating the test to use the new signal constants ensures that the test remains valid and that the bg built-in behaves as expected when resuming jobs.

Also applies to: 281-281


311-311: Updated various test cases to use the new signal constants.

These updates are necessary to ensure that the tests reflect the changes made in the main codebase and continue to test the correct behavior of the bg built-in.

Also applies to: 337-337, 364-364, 419-420, 474-476, 515-515

yash-builtin/src/fg.rs (3)

97-97: Updated imports and usage of new signal types align with the PR objectives.

Also applies to: 144-146, 214-214, 218-219


144-146: Proper handling of signal conversion with error checking enhances robustness.


214-214: Updated test cases to use new signal constants ensure consistency and validity.

Also applies to: 218-219, 241-241, 261-261, 287-287, 317-317, 341-341, 366-366, 425-425, 434-434, 474-474, 489-489

yash-env/src/signal.rs (3)

65-166: Introduction of new signal types Name and Number with comprehensive methods for handling and conversion aligns with the PR objectives.

Also applies to: 168-179, 181-254, 256-263, 298-371


277-296: Introduction of UnknownNameError for robust error handling during signal name parsing enhances the system's reliability.


397-481: The implementation of the Number type with methods for safe and unchecked creation aligns with the need for robust and flexible signal handling.

yash-builtin/src/trap.rs (6)

122-124: Introduced CondSpec module and made it publicly accessible.

This modularization enhances the clarity and maintainability of condition specifications in trap handling.


132-132: Added new imports to support the updated functionality.

These imports are necessary for the new error handling and system interaction functionalities introduced in this file.

Also applies to: 135-135, 138-138


157-157: Updated conditions field to use CondSpec instead of previous type.

This change aligns with the new abstraction for signal conditions, improving the system's flexibility and maintainability.


188-197: Introduced ErrorCause enum to encapsulate specific error scenarios.

This structured approach to error handling allows for more precise error reporting and handling within the trap functionality.


200-208: Defined a new Error struct to represent errors in trap execution.

This new structure enhances error information encapsulation and propagation, aligning with modern Rust error handling practices.


264-275: Updated Command::execute to handle new error structures and CondSpec.

The modifications ensure that the command execution logic is compatible with the new error handling and condition specification mechanisms.

yash-env/src/system/virtual/signal.rs (3)

19-21: Updated imports to reflect changes in signal handling architecture.

These changes are necessary to align with the new signal handling structures introduced in the system.


280-339: Implemented try_from_raw_virtual to convert raw numbers back to signal names.

This reverse mapping is essential for debugging and logging purposes, allowing easier traceability of signal-related issues.


379-419: Defined default effects for signals in the virtual system.

Specifying default effects for each signal helps in managing the expected behavior of signals consistently across the virtual environment.

yash-builtin/src/jobs.rs (5)

99-99: Added import for SharedSystem to support the new signal handling mechanism.


115-115: Refactored Accumulator struct to support new signal handling with show_pid and pgid_only flags.

Also applies to: 177-177, 186-186


127-140: Updated Accumulator::report method to use SharedSystem for state determination, aligning with the new signal handling architecture.


195-195: Ensured that job reporting now utilizes the new signal handling system by passing SharedSystem to the report method.

Also applies to: 202-202


243-243: Updated tests to reflect changes in signal handling and job state reporting.

Also applies to: 264-264, 287-287, 303-303, 311-311, 337-337, 392-392, 437-437, 484-484, 521-521, 548-548, 569-569, 588-588, 608-608

yash-env/src/system/real.rs (7)

19-20: Introduced a new signal module to handle signal operations, aligning with the PR's objective to improve signal handling.


348-352: Implemented new methods validate_signal and signal_number_from_name to support the new signal handling architecture.

Also applies to: 355-357


369-391: Refactored sigaction to use the new signal handling types, improving modularity and maintainability.


Line range hint 394-408: Enhanced caught_signals method to validate and convert raw signal numbers using the new signal handling system.


419-423: Updated kill method to support optional signal numbers, reflecting the new signal handling design.


499-521: Updated wait method to handle new signal types and process states, ensuring compatibility with the updated signal handling system.


685-698: Test case added to verify the correct capturing and handling of signals using the new system.

yash-semantics/src/command/pipeline.rs (2)

630-635: The job control logic correctly updates the job state to stopped due to SIGSTOP.


348-348: Ensure the use of SIGSTOP aligns with the new signal handling strategy.

Verification successful

The use of SIGSTOP aligns with the signal handling strategy across the codebase. The signal is consistently used in assertions, state settings, and signal handling mechanisms.

  • yash-semantics/src/command/pipeline.rs
  • yash-semantics/src/command/compound_command/subshell.rs
  • yash-semantics/src/tests.rs
  • yash-builtin/src/kill.rs
  • yash-builtin/src/trap.rs
  • yash-builtin/src/jobs.rs
  • yash-builtin/src/fg.rs
  • yash-builtin/src/bg.rs
  • yash-env/src/trap.rs
  • yash-env/src/signal.rs
  • yash-builtin/src/wait/status.rs
  • yash-env/src/job.rs
  • yash-env/src/trap/state.rs
  • yash-builtin/src/wait/core.rs
  • yash-env/src/system/real/signal.rs
  • yash-env/src/system/virtual/signal.rs
  • yash-env/src/system/virtual/process.rs
  • yash-env/src/system/virtual.rs
  • yash-env/src/job/fmt.rs
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that SIGSTOP is used correctly across the system.
rg --type rust $'SIGSTOP'

Length of output: 9210

yash-builtin/src/kill/syntax.rs (3)

25-28: Ensure the new Signal type and signal module are correctly integrated.


345-349: Ensure the Command::Send structure is correctly updated to use the new signal types.


193-195: Check the logic for handling multiple signals and ensure it aligns with the new signal handling strategy.

Also applies to: 310-310

Verification successful

The set_signal function and the related test cases indicate that the logic for handling multiple signals is implemented correctly. The function returns an Error::MultipleSignals when more than one signal is specified, and the test cases validate this behavior.

  • The set_signal function checks if signal_origin already contains a field and returns Error::MultipleSignals if it does.
  • The test cases multiple_signals_error_on_option_s, multiple_signals_error_on_option_n, and multiple_signals_error_on_bare_signal_name confirm that the function correctly identifies and handles multiple signals.

The logic for handling multiple signals aligns with the new signal handling strategy.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of multiple signals in the system.
rg --type rust $'MultipleSignals'

Length of output: 622



Script:

#!/bin/bash
# Description: Gather context around the usage of MultipleSignals in yash-builtin/src/kill/syntax.rs
rg --context 5 'MultipleSignals' yash-builtin/src/kill/syntax.rs

Length of output: 2754

yash-env/src/lib.rs (7)

230-230: Ensure proper handling of signals in wait_for_signals.

This method now correctly captures and processes signals using the new signal::Number type, aligning with the PR's objectives to refactor signal handling.


340-349: Validate signal handling in wait_for_subshell.

The method wait_for_subshell correctly integrates the new signal handling by using signal::Name::Chld to wait for child processes. This is a crucial part of the system's robustness in handling subprocesses.


457-457: Confirm the addition of the signal module.

The addition of the signal module is crucial for the new signal handling architecture. This aligns with the PR's goal to refactor and improve signal handling.


472-472: Ensure correct signal handling in tests.

The test wait_for_signal_remembers_signal_in_trap_set correctly sets and checks signal actions, ensuring that the new signal handling is effective even in simulated environments.


539-539: Review test setup for signal handling.

The setup in poll_signals_env correctly initializes the environment for testing signal polling, ensuring that the new signal handling mechanisms are correctly integrated into the testing framework.


562-566: Check correctness of signal raising and polling in tests.

The test poll_signals_some effectively demonstrates the functionality of signal polling by correctly raising and detecting a signal, which is crucial for validating the robustness of the new signal handling mechanisms.


242-242: Check for potential infinite loops in wait_for_signal.

yash-env/src/subshell.rs (1)

656-657: Verify that the parent process correctly unblocks signals.

This script checks if the parent process correctly restores the previous signal mask after the subshell starts. This is crucial to ensure that the parent process does not remain incorrectly blocked on these signals.

yash-env/src/system/virtual/process.rs (9)

20-20: Updated imports to use custom signal types.


82-82: Replaced HashMap<Signal, SignalHandling> with HashMap<signal::Number, SignalHandling> to use the new signal type.


91-91: Updated caught_signals to use signal::Number instead of Signal.


381-385: Implemented signal_handling to retrieve the handling for a given signal number, defaulting to SignalHandling::Default if not set.


394-397: Implemented set_signal_handling to update the signal handling for a given signal number, returning the previous handling.


462-474: Updated raise_signal to handle the new signal types, including proper state changes and delivery based on the signal blocking status.


602-602: Updated unit tests to use the new signal::Number type and verify the behavior of signal handling methods. Ensure that all edge cases are covered in the tests.

Also applies to: 638-638, 766-766, 788-788, 811-811, 827-827, 844-844, 861-861, 881-881, 907-907, 918-918


411-422: Refactored deliver_signal to handle the new signal types and effects. Ensure that the mapping from signal::Number to SignalEffect is correctly implemented.

Verification successful

The mapping from signal::Number to SignalEffect is correctly implemented in the of method of the SignalEffect enum. The method comprehensively handles various signal names and maps them to appropriate SignalEffect variants.

  • Name::Abrt maps to Self::Terminate { core_dump: true }
  • Name::Alrm maps to Self::Terminate { core_dump: false }
  • Name::Bus maps to Self::Terminate { core_dump: true }
  • Name::Chld and Name::Cld map to Self::None
  • Name::Cont maps to Self::Resume
  • Name::Emt maps to Self::Terminate { core_dump: false }
  • Name::Fpe maps to Self::Terminate { core_dump: true }
  • Name::Hup maps to Self::Terminate { core_dump: false }
  • Name::Ill maps to Self::Terminate { core_dump: true }
  • Name::Info maps to Self::Terminate { core_dump: false }
  • Name::Int maps to Self::Terminate { core_dump: false }
  • Name::Io maps to Self::Terminate { core_dump: false }
  • Name::Iot maps to Self::Terminate { core_dump: true }
  • Name::Kill maps to Self::Terminate { core_dump: false }
  • Name::Lost maps to Self::Terminate { core_dump: false }
  • Name::Pipe maps to Self::Terminate { core_dump: false }
  • Name::Poll maps to Self::Terminate { core_dump: false }
  • Name::Prof maps to Self::Terminate { core_dump: false }
  • Name::Pwr maps to Self::Terminate { core_dump: false }
  • Name::Quit maps to Self::Terminate { core_dump: true }
  • Name::Segv maps to Self::Terminate { core_dump: true }
  • Name::Stkflt maps to Self::Terminate { core_dump: false }
  • Name::Stop maps to Self::Suspend
  • Name::Sys maps to Self::Terminate { core_dump: true }
  • Name::Term maps to Self::Terminate { core_dump: false }
  • Name::Thr maps to Self::Terminate { core_dump: false }
  • Name::Trap maps to Self::Terminate { core_dump: true }
  • Name::Tstp, Name::Ttin, and Name::Ttou map to Self::Suspend
  • Name::Urg maps to Self::None
  • Name::Usr1 and Name::Usr2 map to Self::Terminate { core_dump: false }
  • Name::Vtalrm maps to Self::Terminate { core_dump: false }
  • Name::Winch maps to Self::None
  • Name::Xcpu maps to Self::Terminate { core_dump: true }
  • Name::Xfsz maps to Self::Terminate { core_dump: true }
  • Name::Rtmin(_) and Name::Rtmax(_) map to Self::Terminate { core_dump: false }

This confirms that the mapping is correctly implemented.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct mapping from `signal::Number` to `SignalEffect`.

# Test: Search for usage of `SignalEffect::of`. Expect: Correct mappings.
rg --type rust $'SignalEffect::of'

Length of output: 147



Script:

#!/bin/bash
# Locate the definition of `SignalEffect::of` and examine its implementation.
ast-grep --lang rust --pattern 'impl SignalEffect {
  $_
  fn of($_) -> $_ {
    $$$
  }
  $$$
}'

Length of output: 99



Script:

#!/bin/bash
# Locate the definition of `SignalEffect` and then search for the `of` method within its implementation.

# Search for the definition of `SignalEffect`.
ast-grep --lang rust --pattern 'struct SignalEffect {
  $$$
}' || ast-grep --lang rust --pattern 'enum SignalEffect {
  $$$
}'

# Search for the `of` method within the `SignalEffect` implementation.
ast-grep --lang rust --pattern 'impl SignalEffect {
  $_
  fn of($_) -> $_ {
    $$$
  }
  $$$
}'

Length of output: 164



Script:

#!/bin/bash
# Locate the definition of `SignalEffect` and then search for the `of` method within its implementation.

# Search for the definition of `SignalEffect` using a broader pattern.
rg --type rust 'SignalEffect'

# Search for the `of` method within the `SignalEffect` implementation using a broader pattern.
rg --type rust 'fn of'

Length of output: 924



Script:

#!/bin/bash
# Extract and examine the `SignalEffect` enum definition and the `of` method implementation from `yash-env/src/system/virtual/signal.rs`.

# Extract the `SignalEffect` enum definition.
sed -n '/pub enum SignalEffect {/,/}/p' yash-env/src/system/virtual/signal.rs

# Extract the `of` method implementation.
sed -n '/impl SignalEffect {/,/}/p' yash-env/src/system/virtual/signal.rs

Length of output: 448



Script:

#!/bin/bash
# Extract the complete definitions of the `SignalEffect` enum and the `of` method from `yash-env/src/system/virtual/signal.rs`.

# Extract the complete `SignalEffect` enum definition.
sed -n '/pub enum SignalEffect {/,/}/p' yash-env/src/system/virtual/signal.rs

# Extract the complete `of` method implementation.
sed -n '/impl SignalEffect {/,/^}/p' yash-env/src/system/virtual/signal.rs

Length of output: 2731


374-374: Modified deliver_signal to convert Signal to signal::Number using from_signal_virtual. Ensure that all signal conversions are handled correctly across different system types.

yash-env/src/trap/state.rs (1)

21-21: Ensure that the Condition and SignalSystem are correctly utilized in the context of the new signal handling architecture.

Verification successful

The usage of Condition and SignalSystem is consistent across the codebase and aligns with the new signal handling architecture.

  • Condition is used in various contexts, including signal handling and error conditions.
  • SignalSystem is implemented and utilized correctly in the yash-env module.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `Condition` and `SignalSystem` across the codebase to ensure consistency.

# Test: Search for the usage of `Condition` and `SignalSystem`. Expect: Consistent usage across the codebase.
rg --type rust $'Condition|SignalSystem'

Length of output: 19708

yash-env/src/trap.rs (23)

39-42: Refactored imports and re-exported entities to align with the new signal handling architecture.


54-61: Added methods for signal name and number conversion, enhancing the abstraction over signal handling.


164-169: Improved error handling by explicitly checking for non-trappable signals (SIGKILL and SIGSTOP) before setting actions.


239-252: Refactored enter_subshell method to handle signal-specific behaviors more explicitly, improving readability and maintainability.


259-261: Ensure that signals SIGINT and SIGQUIT are ignored when specified, which is critical for correct shell behavior in subshells.


Line range hint 303-367: Significant enhancements in internal signal handling methods, allowing for more granular control over signal behaviors in different shell states.


Line range hint 413-501: The test suite has been expanded to cover the new functionalities and changes in signal handling. Ensure that all new behaviors are adequately tested.


509-523: Correct handling of SIGKILL and SIGSTOP in tests, which should not be trappable, aligning with POSIX standards.


Line range hint 554-600: Tests for basic iteration over traps show that the state management and retrieval are functioning as expected.


Line range hint 614-631: Tests for setting traps in a subshell context are comprehensive and demonstrate the isolation between main shell and subshell environments.


Line range hint 645-684: Tests for entering subshells with different types of traps (ignore vs command) are thorough and validate the expected behavior changes.


Line range hint 694-710: The handling of SIGCHLD in subshells is correctly implemented, ensuring that internal handlers are managed appropriately.


Line range hint 720-788: Comprehensive testing of internal handlers for various signals (SIGINT, SIGTERM, SIGQUIT, etc.) in subshell contexts.


Line range hint 798-866: Tests for stopper signals (SIGTSTP, SIGTTIN, SIGTTOU) in subshells are well-implemented, ensuring that these signals are handled correctly in interactive job-controlling shells.


Line range hint 876-910: Tests for setting traps after entering a subshell ensure that parent states are cleared as expected, which is crucial for correct signal handling in nested environments.


920-933: Tests for nested subshells demonstrate the correct clearing of parent states, ensuring isolation between shell layers.


Line range hint 942-986: Tests for ignoring SIGINT and SIGQUIT when entering a subshell with actions set, and without actions set, are crucial for ensuring that the shell behaves correctly under different configurations.


Line range hint 992-1013: Tests for keeping stopper handlers ignored when specified, and the absence of stopper handlers, validate the shell's behavior in handling job control signals.


Line range hint 1049-1131: Tests for catching and handling signals are comprehensive, covering various scenarios and ensuring that the trap states are managed correctly.


1146-1166: Tests for enabling and disabling internal handlers cover a wide range of scenarios, ensuring robustness in the shell's signal handling capabilities.


Line range hint 1177-1230: The tests for disabling internal handlers after enabling them multiple times, and without enabling, are thorough and ensure that the shell's internal state is managed correctly across different operations.


1262-1268: Reenabling internal handlers after disabling them tests the shell's ability to restore signal handling states, which is crucial for dynamic signal management in interactive shells.


1277-1279: Testing the setting of a trap to ignore after enabling an internal handler for SIGCHLD ensures that the shell can handle complex signal management scenarios.

yash-env/src/job.rs (4)

45-45: Added import for the new signal module.

This change aligns with the PR's objective to replace nix::signal::Signal with signal::Number and other signal-related types.


132-132: Updated ProcessResult to use signal::Number.

This change is crucial for decoupling from the nix library and using the newly defined signal types, which is a key objective of this PR.

Also applies to: 136-139


190-190: Method ProcessState::stopped now correctly uses signal::Number.

This update is necessary for the internal consistency of the new signal handling system.


931-931: Updated test cases to use signal::Number and ProcessState::stopped.

These changes ensure that the test suite is aligned with the new signal handling implementation, which is essential for validating the changes made in this PR.

Also applies to: 1126-1126, 1153-1153, 1169-1169, 1178-1178, 1197-1199, 1245-1247, 1279-1280, 1318-1319, 1342-1342, 1371-1371, 1385-1386, 1402-1404, 1430-1432, 1458-1460, 1477-1477, 1488-1488, 1500-1500, 1511-1511, 1516-1516

yash-env/src/system.rs (7)

643-665: Review the implementation of tcsetpgrp_without_block for correct signal handling.

Verification successful

The implementation of tcsetpgrp_without_block in yash-env/src/system.rs appears to handle signals correctly by unblocking SIGTTOU, setting the process group, and then restoring the signal mask and signal action. The usages in yash-semantics/src/command/pipeline.rs and yash-builtin/src/fg.rs also seem to follow the correct procedure for handling foreground process group switching.

  • yash-semantics/src/command/pipeline.rs ensures that tcsetpgrp_without_block is called when job control is enabled and the shell is in the foreground.
  • yash-builtin/src/fg.rs uses tcsetpgrp_without_block to put the target job in the foreground before sending the SIGCONT signal.

These usages align with the expected behavior for handling signals during process group switching.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of foreground process group switching with signal handling.

# Test: Search for usages of `tcsetpgrp_without_block` to ensure it handles signals correctly.
rg --type rust $'tcsetpgrp_without_block'

Length of output: 556



Script:

#!/bin/bash
# Extract the definition of `tcsetpgrp_without_block` from `yash-env/src/system.rs`
ast-grep --lang rust --pattern 'fn tcsetpgrp_without_block(&mut self, fd: Fd, pgid: Pid) -> Result<()> { $$$ }'

# Extract the usage of `tcsetpgrp_without_block` in `yash-semantics/src/command/pipeline.rs`
rg --context 5 --type rust 'tcsetpgrp_without_block' yash-semantics/src/command/pipeline.rs

# Extract the usage of `tcsetpgrp_without_block` in `yash-builtin/src/fg.rs`
rg --context 5 --type rust 'tcsetpgrp_without_block' yash-builtin/src/fg.rs

Length of output: 3458


227-234: Validate the implementation of validate_signal and signal_number_from_name.

Verification successful

The implementations of validate_signal and signal_number_from_name have been successfully extracted from the relevant files. Here are the details:

  • In yash-env/src/system.rs, these functions delegate their work to another implementation via self.0.borrow().
  • In yash-env/src/system/real.rs and yash-env/src/system/virtual.rs, the functions are implemented to handle real and virtual signals respectively.

The implementations appear to be consistent and correctly handle the signal validation and conversion. Therefore, the review comment has been verified successfully.

  • validate_signal and signal_number_from_name are implemented correctly in yash-env/src/system.rs, yash-env/src/system/real.rs, and yash-env/src/system/virtual.rs.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of signal validation and conversion functions.

# Test: Search for usages of these functions to ensure they are used correctly.
rg --type rust $'validate_signal|signal_number_from_name'

Length of output: 4625



Script:

#!/bin/bash
# Extract the implementation of validate_signal in yash-env/src/system.rs
ast-grep --lang rust --pattern 'fn validate_signal(&self, number: signal::RawNumber) -> Option<(signal::Name, signal::Number)> { $$$ }' yash-env/src/system.rs

# Extract the implementation of signal_number_from_name in yash-env/src/system.rs
ast-grep --lang rust --pattern 'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> { $$$ }' yash-env/src/system.rs

# Extract the implementation of validate_signal in yash-env/src/system/real.rs
ast-grep --lang rust --pattern 'fn validate_signal(&self, number: signal::RawNumber) -> Option<(signal::Name, signal::Number)> { $$$ }' yash-env/src/system/real.rs

# Extract the implementation of signal_number_from_name in yash-env/src/system/real.rs
ast-grep --lang rust --pattern 'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> { $$$ }' yash-env/src/system/real.rs

# Extract the implementation of validate_signal in yash-env/src/system/virtual.rs
ast-grep --lang rust --pattern 'fn validate_signal(&self, number: signal::RawNumber) -> Option<(signal::Name, signal::Number)> { $$$ }' yash-env/src/system/virtual.rs

# Extract the implementation of signal_number_from_name in yash-env/src/system/virtual.rs
ast-grep --lang rust --pattern 'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> { $$$ }' yash-env/src/system/virtual.rs

Length of output: 2763


1182-1190: Review the sigmask and set_signal_handling methods for correct signal masking and handling.

Also applies to: 1207-1207

Verification successful

The sigmask and set_signal_handling methods are implemented and used in various parts of the codebase. The sigmask method is defined in yash-env/src/system.rs and is used in subshell.rs, trap.rs, and system.rs. The set_signal_handling method is defined in trap.rs and system.rs and is used in trap.rs, system.rs, and virtual/process.rs.

The implementations of both methods appear to be consistent with their intended purposes. The sigmask method correctly handles signal masking, and the set_signal_handling method correctly sets signal handling.

  • sigmask method implementation in system.rs:

    • Correctly converts the signal number to a signal name and back to a signal number.
    • Uses SigSet to manage signal sets.
    • Calls the sigmask method on the system object to apply the signal mask.
  • set_signal_handling method implementation in trap.rs and system.rs:

    • Correctly sets the signal handling for the specified signal.

Based on the gathered information, the methods are implemented and used correctly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/binbash
# Description: Verify the correct implementation of signal masking and handling.

# Test: Search for usages of `sigmask` and `set_signal_handling` to ensure they are used correctly.
rg --type rust $'sigmask|set_signal_handling'

Length of output: 5823



Script:

#!/bin/bash
# Description: Verify the implementation of the `sigmask` method and its usage in the codebase.

# Check the implementation of the `sigmask` method in `system.rs`.
ast-grep --lang rust --pattern 'fn sigmask(&mut self, how: SigmaskHow, signal: signal::Number) -> Result<()> { $$$ }'

# Check the usage of the `sigmask` method in `subshell.rs`.
rg 'sigmask' yash-env/src/subshell.rs

# Check the usage of the `sigmask` method in `trap.rs`.
rg 'sigmask' yash-env/src/trap.rs

# Check the usage of the `sigmask` method in `system.rs`.
rg 'sigmask' yash-env/src/system.rs

Length of output: 2633


Script:

#!/bin/bash
# Description: Verify the implementation of the `set_signal_handling` method and its usage in the codebase.

# Check the implementation of the `set_signal_handling` method in `trap.rs`.
ast-grep --lang rust --pattern 'fn set_signal_handling(&mut self, signal: signal::Number, handling: SignalHandling) -> Result<()> { $$$ }'

# Check the implementation of the `set_signal_handling` method in `system.rs`.
ast-grep --lang rust --pattern 'fn set_signal_handling(&mut self, signal: signal::Number, handling: SignalHandling) -> Result<()> { $$$ }'

# Check the usage of the `set_signal_handling` method in `trap.rs`.
rg 'set_signal_handling' yash-env/src/trap.rs

# Check the usage of the `set_signal_handling` method in `system.rs`.
rg 'set_signal_handling' yash-env/src/system.rs

# Check the usage of the `set_signal_handling` method in `virtual/process.rs`.
rg 'set_signal_handling' yash-env/src/system/virtual/process.rs

Length of output: 2332


1515-1525: Review the wake method in AsyncSignal for correct signal handling.

Verification successful

The wake method in AsyncSignal appears to be implemented correctly, but we need to verify its usage throughout the codebase to ensure it handles signals correctly. The rg output shows multiple instances of wake being used, but we need to focus on the specific context of signal handling.

To gather more information, let's search for the AsyncSignal struct and its wake method usage in the codebase to ensure it is correctly integrated with the signal handling logic.


Let's correct the ast-grep pattern for the impl AsyncSignal block and re-run the search to gather the necessary information.


The wake method in the AsyncSignal struct is implemented correctly and is designed to wake up tasks waiting for specific signals. The method iterates through the awaiters, upgrades weak references, updates the signal status, and wakes the associated waker if present.

Given the context and the results from the shell scripts, the wake method appears to be correctly implemented and integrated with the signal handling logic.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of signal waking in asynchronous signal handling.

# Test: Search for usages of the `wake` method to ensure it handles signals correctly.
rg --type rust $'wake'

Length of output: 10559



Script:

#!/bin/bash
# Search for the definition of the `AsyncSignal` struct and its `wake` method usage in the codebase.
ast-grep --lang rust --pattern 'struct AsyncSignal { $$$ }'
ast-grep --lang rust --pattern 'impl AsyncSignal { $$$ wake(&mut self, $_) { $$$ } $$$ }'

Length of output: 793



Script:

#!/bin/bash
# Corrected search for the implementation of the `AsyncSignal` struct and its `wake` method usage in the codebase.
ast-grep --lang rust --pattern 'impl AsyncSignal { $$$ }'
ast-grep --lang rust --pattern 'impl AsyncSignal { $$$ fn wake(&mut self, $_) { $$$ } $$$ }'

Length of output: 3426


673-698: Review the new methods signal_name_from_number and signal_number_from_exit_status for correctness.

Verification successful

The methods signal_name_from_number and signal_number_from_exit_status have been correctly implemented and are used appropriately across multiple files. The validate_signal method, which is crucial for these methods, is also correctly implemented.

  • signal_name_from_number converts a signal number to a signal name using validate_signal.
  • signal_number_from_exit_status converts an exit status to a signal number, supporting multiple offsets and using validate_signal.

The usage of these methods in various files confirms their integration into the system.

  • yash-env/src/trap.rs
  • yash-env/src/trap/cond.rs
  • yash-env/src/job/fmt.rs
  • yash-builtin/src/trap/cond.rs
  • yash-builtin/src/kill/print.rs
  • yash-builtin/src/kill/signal.rs

These methods are used to handle signals and exit statuses correctly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of signal number and name conversion methods.

# Test: Search for usages of these methods to ensure they are used correctly.
rg --type rust $'signal_name_from_number|signal_number_from_exit_status'

Length of output: 1626



Script:

#!/bin/bash
# Description: Verify the correct implementation of signal number and name conversion methods.

# Test: Extract the implementation of `signal_name_from_number` and `signal_number_from_exit_status` methods.
ast-grep --lang rust --pattern $'fn signal_name_from_number(&self, number: signal::Number) -> signal::Name {
  $_$
}' yash-env/src/system.rs

ast-grep --lang rust --pattern $'fn signal_number_from_exit_status(&self, status: ExitStatus) -> Option<signal::Number> {
  $_$
}' yash-env/src/system.rs

# Test: Extract the implementation of `validate_signal` method used in both methods.
ast-grep --lang rust --pattern $'fn validate_signal(&self, raw_number: i32) -> Result<(signal::Name, signal::Number), Error> {
  $_$
}' yash-env/src/system.rs

Length of output: 456


Script:

#!/bin/bash
# Description: Verify the correct usage of `signal_name_from_number` and `signal_number_from_exit_status` methods.

# Test: Extract the usage of `signal_name_from_number` in identified files.
rg --type rust 'signal_name_from_number' yash-env/src/trap.rs yash-env/src/trap/cond.rs yash-env/src/job/fmt.rs yash-builtin/src/trap/cond.rs yash-builtin/src/kill/print.rs yash-builtin/src/kill/signal.rs

# Test: Extract the usage of `signal_number_from_exit_status` in identified files.
rg --type rust 'signal_number_from_exit_status' yash-env/src/trap.rs yash-env/src/trap/cond.rs yash-env/src/job/fmt.rs yash-builtin/src/trap/cond.rs yash-builtin/src/kill/print.rs yash-builtin/src/kill/signal.rs

Length of output: 1488



Script:

#!/bin/bash
# Description: Re-verify the correct implementation of signal number and name conversion methods.

# Test: Extract the implementation of `signal_name_from_number` method.
rg --type rust 'fn signal_name_from_number' yash-env/src/system.rs -A 10

# Test: Extract the implementation of `signal_number_from_exit_status` method.
rg --type rust 'fn signal_number_from_exit_status' yash-env/src/system.rs -A 10

# Test: Extract the implementation of `validate_signal` method used in both methods.
rg --type rust 'fn validate_signal' yash-env/src/system.rs -A 10

Length of output: 2433


Line range hint 269-298: Review the implementation of sigaction and caught_signals.

Verification successful

To verify the correct implementation and usage of the sigaction and caught_signals functions, we need to review their definitions and usages in the relevant files. The search results indicate that these functions are defined and used in multiple files, including system.rs, virtual.rs, and real.rs.

Let's start by examining the implementation of these functions in system.rs, virtual.rs, and real.rs.


The implementations of the sigaction and caught_signals functions have been extracted from the relevant files. Here are the details:

  • In system.rs, the caught_signals function is defined as:

    fn caught_signals(&mut self) -> Vec<signal::Number> {
        self.0.borrow_mut().caught_signals()
    }
  • In virtual.rs, the caught_signals function is defined as:

    fn caught_signals(&mut self) -> Vec<signal::Number> {
        std::mem::take(&mut self.current_process_mut().caught_signals)
    }
  • In real.rs, the caught_signals function is defined as:

    fn caught_signals(&mut self) -> Vec<signal::Number> {
        let mut signals = Vec::new();
        for slot in &CAUGHT_SIGNALS {
            // Need a fence to ensure we examine the slots in order.
            compiler_fence(Ordering::Acquire);
    
            let signal = slot.swap(0, Ordering::Relaxed);
            if signal == 0 {
                // The `catch_signal` function always fills the first unused
                // slot, so there is no more slot filled with a signal.
                break;
            }
    
            if let Some((_name, number)) = self.validate_signal(signal as signal::RawNumber) {
                signals.push(number)
            } else {
                // ignore unknown signal
            }
        }
        signals
    }

The sigaction function implementations were not captured in the output, indicating they might be defined differently or in a more complex manner. To ensure we have a complete understanding, we should re-run the script to capture the sigaction implementations specifically.


The previous attempt to extract the sigaction function implementations did not produce any output. This suggests that the pattern used might not have matched the actual function definitions, or the functions might be defined in a more complex manner.

To ensure we capture the sigaction implementations correctly, let's refine our approach by searching for the function definitions using rg with a more flexible pattern.


The sigaction and caught_signals functions have been successfully extracted from the relevant files. Here are the details:

  • In system.rs, the sigaction function is defined as:

    fn sigaction(
        &mut self,
        signal: signal::Number,
        action: SignalHandling,
    ) -> Result<SignalHandling> {
        self.0.borrow_mut().sigaction(signal, action)
    }
  • In virtual.rs, the sigaction function is defined as:

    fn sigaction(
        &mut self,
        signal: signal::Number,
        action: SignalHandling,
    ) -> Result<SignalHandling> {
        let mut process = self.current_process_mut();
        Ok(process.set_signal_handling(signal, action))
    }
  • In real.rs, the sigaction function is defined as:

    fn sigaction(
        &mut self,
        signal: signal::Number,
        handling: SignalHandling,
    ) -> Result<SignalHandling> {
        unsafe {
            let new_action = handling.to_sigaction();
    
            let mut old_action = MaybeUninit::<nix::libc::sigaction>::uninit();
            let old_mask_ptr = std::ptr::addr_of_mut!((*old_action.as_mut_ptr()).sa_mask);
            // POSIX requires *all* sigset_t objects to be initialized before use.
            nix::libc::sigemptyset(old_mask_ptr).errno_if_m1()?;
    
            nix::libc::sigaction(
                signal.as_raw(),
                new_action.as_ptr(),
                old_action.as_mut_ptr(),
            )
            .errno_if_m1()?;
    
            let old_handling = SignalHandling::from_sigaction(&old_action);

The implementations of both sigaction and caught_signals functions appear to be consistent and correctly handle signal actions and caught signals. The sigaction function sets the signal handler, and caught_signals retrieves the list of caught signals.

Based on the extracted implementations, the functions seem to be implemented correctly and used consistently across the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation and usage of signal action setting and signal catching.

# Test: Search for usages of these functions to ensure they are used correctly and that signal handling is consistent.
rg --type rust $'sigaction|caught_signals'

Length of output: 7653



Script:

#!/bin/bash
# Extract the implementation of sigaction and caught_signals functions from system.rs, virtual.rs, and real.rs

# Extract from system.rs
ast-grep --lang rust --pattern $'fn sigaction($_, $_) {
  $$$
}' yash-env/src/system.rs

ast-grep --lang rust --pattern $'fn caught_signals(&mut self) -> Vec<signal::Number> {
  $$$
}' yash-env/src/system.rs

# Extract from virtual.rs
ast-grep --lang rust --pattern $'fn sigaction($_, $_) {
  $$$
}' yash-env/src/system/virtual.rs

ast-grep --lang rust --pattern $'fn caught_signals(&mut self) -> Vec<signal::Number> {
  $$$
}' yash-env/src/system/virtual.rs

# Extract from real.rs
ast-grep --lang rust --pattern $'fn sigaction($_, $_) {
  $$$
}' yash-env/src/system/real.rs

ast-grep --lang rust --pattern $'fn caught_signals(&mut self) -> Vec<signal::Number> {
  $$$
}' yash-env/src/system/real.rs

Length of output: 2522



Script:

#!/bin/bash
# Extract the implementation of sigaction functions from system.rs, virtual.rs, and real.rs

# Extract from system.rs
ast-grep --lang rust --pattern $'fn sigaction($_, $_) {
  $$$
}' yash-env/src/system.rs

# Extract from virtual.rs
ast-grep --lang rust --pattern $'fn sigaction($_, $_) {
  $$$
}' yash-env/src/system/virtual.rs

# Extract from real.rs
ast-grep --lang rust --pattern $'fn sigaction($_, $_) {
  $$$
}' yash-env/src/system/real.rs

Length of output: 279



Script:

#!/bin/bash
# Extract the implementation of sigaction functions from system.rs, virtual.rs, and real.rs using rg

# Extract from system.rs
rg --type rust 'fn sigaction' yash-env/src/system.rs -A 20

# Extract from virtual.rs
rg --type rust 'fn sigaction' yash-env/src/system/virtual.rs -A 20

# Extract from real.rs
rg --type rust 'fn sigaction' yash-env/src/system/real.rs -A 20

Length of output: 3390


311-311: Ensure the kill function correctly handles the optional signal parameter.

Verification successful

The kill function implementations in yash-env/src/system.rs, yash-env/src/system/real.rs, and yash-env/src/system/virtual.rs have been successfully extracted. Here are the key points:

  • In yash-env/src/system.rs, the kill function delegates the call to another kill function, passing the target and signal parameters.
  • In yash-env/src/system/real.rs, the kill function uses the nix::libc::kill function, correctly handling the optional signal parameter by mapping it to a raw value.
  • In yash-env/src/system/virtual.rs, the kill function handles the signal parameter and sends it to processes based on the target.

These implementations indicate that the kill function correctly handles the optional signal parameter.

  • yash-env/src/system.rs
  • yash-env/src/system/real.rs
  • yash-env/src/system/virtual.rs
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of the `kill` function with optional signal parameter.

# Test: Search for usages of the `kill` function to ensure it is used correctly.
rg --type rust $'kill'

Length of output: 5915



Script:

#!/bin/bash
# Extract the implementation of the `kill` function from `yash-env/src/system.rs`
ast-grep --lang rust --pattern $'fn kill($_, $_) {
  $$$
}' yash-env/src/system.rs

Length of output: 83



Script:

#!/bin/bash
# Search for the definition of the `kill` function across the entire codebase
ast-grep --lang rust --pattern $'fn kill($_, $_) {
  $$$
}'

Length of output: 60



Script:

#!/bin/bash
# Search for the definition of the `kill` function across the entire codebase using `rg`
rg 'fn kill'

Length of output: 735



Script:

#!/bin/bash
# Extract the implementation of the `kill` function from relevant files
ast-grep --lang rust --pattern $'fn kill($_, $_) {
  $$$
}' yash-env/src/system.rs yash-env/src/system/real.rs yash-env/src/system/virtual.rs

Length of output: 142



Script:

#!/bin/bash
# Search for the definition of the `kill` function in specific files using `rg`
rg 'fn kill' yash-env/src/system.rs yash-env/src/system/real.rs yash-env/src/system/virtual.rs

Length of output: 601



Script:

#!/bin/bash
# Extract the implementation of the `kill` function from specific files
rg -A 10 'fn kill' yash-env/src/system.rs yash-env/src/system/real.rs yash-env/src/system/virtual.rs

Length of output: 6575

yash-env/src/system/virtual.rs (12)

635-639: Validate the new signal handling functions for correctness.

The implementation of validate_signal correctly checks for a non-zero signal number and attempts to convert it to a signal::Name and signal::Number. This aligns with the PR's objective to handle signals more robustly.


641-644: Check the implementation of signal_number_from_name.

The method signal_number_from_name correctly retrieves the raw virtual number from a signal name. This is a straightforward and efficient implementation.


673-677: Review changes to sigaction method.

The updated sigaction method now correctly handles the new signal handling structure, which is part of the PR's objectives to enhance signal handling.


697-697: Examine the modifications to the kill method.

The kill method has been updated to use the new signal::Number type, which is consistent with the rest of the changes in the PR. The method's logic remains correct and aligns with the expected behavior.


1078-1078: Check the helper function send_signal_to_processes.

The function send_signal_to_processes has been correctly updated to handle the new signal types. It iterates over processes and sends signals appropriately, which is crucial for the virtual system's operation.


1105-1105: Review the raise_sigchld function.

The raise_sigchld function is correctly raising the SIGCHLD signal without changing the process state, which is used to notify the parent process of changes in the child process's state.


1840-1846: Ensure correct handling of signals in the kill method.

The kill method's handling of SIGINT and its impact on the process state is correctly implemented. The method's behavior aligns with the expected outcomes described in the PR.


1856-1856: Verify error handling in the kill method.

The method correctly handles the case where a non-existent process ID is targeted, returning the appropriate error code ESRCH.


1881-1889: Check the behavior of kill when sending SIGTERM to all processes.

The method correctly handles the scenario where SIGTERM is sent to all processes, ensuring that each process's state is updated appropriately.


1915-1937: Review the handling of SIGQUIT in the kill method.

The method correctly handles the scenario where SIGQUIT is sent to all processes in the same group, ensuring that each process's state is updated appropriately, including the correct handling of core dumps.


Line range hint 1963-1983: Examine the handling of SIGHUP in the kill method.

The method correctly handles the scenario where SIGHUP is sent to a specific process group, ensuring that each affected process's state is updated appropriately.


2001-2001: Check the handling of SIGCONT in the kill method.

The method correctly handles the scenario where SIGCONT is sent to a process group, ensuring that the process state remains running if it was already running.

@@ -250,7 +249,7 @@ impl Env {
/// [`wait_for_signals`](Self::wait_for_signals) but does not wait for
/// signals to be caught. Instead, it only checks if any signals have been
/// caught but not yet consumed in the [`SharedSystem`].
pub fn poll_signals(&mut self) -> Option<Rc<[Signal]>> {
pub fn poll_signals(&mut self) -> Option<Rc<[signal::Number]>> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review efficiency of poll_signals.

Consider optimizing the poll_signals method to reduce overhead by minimizing context switches and potentially using more efficient polling mechanisms.

yash-builtin/src/trap.rs Show resolved Hide resolved
yash-env/src/subshell.rs Show resolved Hide resolved
yash-env/src/subshell.rs Show resolved Hide resolved
yash-env/src/system.rs Show resolved Hide resolved
yash-env/src/system/virtual/signal.rs Show resolved Hide resolved
yash-builtin/src/kill/syntax.rs Outdated Show resolved Hide resolved
Comment on lines +40 to +51
- `Env::wait_for_signal`
- `Env::wait_for_signals`
- `job::ProcessState::stopped`
- `system::System::caught_signals`
- `system::System::kill`
- `system::System::sigaction`
- `system::virtual::Process::signal_handling`
- `system::virtual::Process::set_signal_handling`
- `trap::TrapSet::catch_signal`
- `trap::TrapSet::take_caught_signal`
- `trap::TrapSet::take_signal_if_caught`
- `system::virtual::SignalEffect::of` now takes a `signal::Number` parameter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust the indentation of the unordered list to match the expected level.

-    - `Env::wait_for_signal`
-    - `Env::wait_for_signals`
-    - `job::ProcessState::stopped`
-    - `system::System::caught_signals`
-    - `system::System::kill`
-    - `system::System::sigaction`
-    - `system::virtual::Process::signal_handling`
-    - `system::virtual::Process::set_signal_handling`
-    - `trap::TrapSet::catch_signal`
-    - `trap::TrapSet::take_caught_signal`
-    - `trap::TrapSet::take_signal_if_caught`
+  - `Env::wait_for_signal`
+  - `Env::wait_for_signals`
+  - `job::ProcessState::stopped`
+  - `system::System::caught_signals`
+  - `system::System::kill`
+  - `system::System::sigaction`
+  - `system::virtual::Process::signal_handling`
+  - `system::virtual::Process::set_signal_handling`
+  - `trap::TrapSet::catch_signal`
+  - `trap::TrapSet::take_caught_signal`
+  - `trap::TrapSet::take_signal_if_caught`
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- `Env::wait_for_signal`
- `Env::wait_for_signals`
- `job::ProcessState::stopped`
- `system::System::caught_signals`
- `system::System::kill`
- `system::System::sigaction`
- `system::virtual::Process::signal_handling`
- `system::virtual::Process::set_signal_handling`
- `trap::TrapSet::catch_signal`
- `trap::TrapSet::take_caught_signal`
- `trap::TrapSet::take_signal_if_caught`
- `system::virtual::SignalEffect::of` now takes a `signal::Number` parameter
- `Env::wait_for_signal`
- `Env::wait_for_signals`
- `job::ProcessState::stopped`
- `system::System::caught_signals`
- `system::System::kill`
- `system::System::sigaction`
- `system::virtual::Process::signal_handling`
- `system::virtual::Process::set_signal_handling`
- `trap::TrapSet::catch_signal`
- `trap::TrapSet::take_caught_signal`
- `trap::TrapSet::take_signal_if_caught`
- `system::virtual::SignalEffect::of` now takes a `signal::Number` parameter
Tools
Markdownlint

40-40: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


41-41: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


42-42: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


43-43: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


44-44: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


45-45: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


46-46: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


47-47: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


48-48: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


49-49: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


50-50: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

Comment on lines 1112 to 1121
#[inline]
fn signal_name_from_number(&self, number: signal::Number) -> signal::Name {
SystemEx::signal_name_from_number(self, number)
}

#[inline]
fn signal_number_from_name(&self, name: signal::Name) -> signal::Number {
System::signal_number_from_name(self, name)
.unwrap_or_else(|| panic!("unsupported signal name: {name:?}"))
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The implementations of the methods signal_name_from_number and signal_number_from_name have been extracted. Here's the analysis:

  • signal_name_from_number:

    • In yash-env/src/system.rs (line 683), it uses self.validate_signal(number.as_raw()).unwrap().0, which could panic if the signal is not valid.
    • In yash-env/src/system.rs (line 1114), it delegates to SystemEx::signal_name_from_number.
  • signal_number_from_name:

    • In yash-env/src/system.rs (line 1120), it uses unwrap_or_else(|| panic!("unsupported signal name: {name:?}")), which explicitly panics on unsupported signal names.
    • Other implementations return Option<signal::Number>, which is safer as it allows handling of unsupported signals without panicking.

The methods in yash-env/src/system.rs do not handle unsupported signals gracefully and can cause panics. This confirms the review comment's concern.

  • yash-env/src/system.rs:
    • Line 683: self.validate_signal(number.as_raw()).unwrap().0
    • Line 1120: System::signal_number_from_name(self, name).unwrap_or_else(|| panic!("unsupported signal name: {name:?}"))
Analysis chain

Ensure that the signal_name_from_number and signal_number_from_name methods handle unsupported signals correctly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of unsupported signals in conversion methods.

# Test: Search for usages of these methods to ensure they handle errors correctly.
rg --type rust $'signal_name_from_number|signal_number_from_name'

Length of output: 4444



Script:

#!/bin/bash
# Extract the implementation of signal_name_from_number and signal_number_from_name methods
ast-grep --lang rust --pattern 'fn signal_name_from_number($_, $_) { $$$ }'
ast-grep --lang rust --pattern 'fn signal_number_from_name($_, $_) { $$$ }'

# Extract the usages of these methods to check for error handling
rg 'signal_name_from_number'
rg 'signal_number_from_name'

Length of output: 5615



Script:

#!/bin/bash
# Extract the full implementation of signal_name_from_number and signal_number_from_name methods
ast-grep --lang rust --pattern 'fn signal_name_from_number($_, $_) -> $_ { $$$ }'
ast-grep --lang rust --pattern 'fn signal_number_from_name($_, $_) -> $_ { $$$ }'

Length of output: 2136

@magicant magicant mentioned this pull request Jun 8, 2024
12 tasks
This commit modifies the `SignalSystem::signal_number_from_name` method
to return `Option<signal::Number>` instead of `signal::Number`. This
change is made to match the behavior of the method with the
`System::signal_number_from_name` method. Previously, these methods had
slightly different behaviors, which was confusing.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7c8518d and 2e4f8b9.

Files selected for processing (3)
  • yash-builtin/src/trap/syntax.rs (14 hunks)
  • yash-env/src/system.rs (23 hunks)
  • yash-env/src/trap.rs (65 hunks)
Files not summarized due to errors (1)
  • yash-env/src/trap.rs: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (1)
  • yash-builtin/src/trap/syntax.rs
Additional context used
Learnings (1)
yash-env/src/system.rs (2)
User: magicant
PR: magicant/yash-rs#367
File: yash-env/src/system.rs:57-57
Timestamp: 2024-06-08T02:51:51.839Z
Learning: The `yash-env/src/subshell.rs` module depends on `SigSet`, which requires `nix::sys::signal::Signal`. Plans are in place to remove `SigSet` in a future PR, and some existing methods like `tcsetpgrp_with_block` still depend on `nix::sys::signal::Signal`.
User: magicant
PR: magicant/yash-rs#367
File: yash-env/src/subshell.rs:40-40
Timestamp: 2024-06-08T02:49:23.406Z
Learning: The `yash-env/src/subshell.rs` module depends on `SigSet`, which requires `nix::sys::signal::Signal`. Plans are in place to remove `SigSet` in a future PR.
Additional comments not posted (9)
yash-env/src/trap.rs (1)

54-54: Ensure that the system supports all required signals.

Also applies to: 74-75

Verification successful

The implementations of the signal_number_from_name function across different files indicate that the function delegates the signal name to number conversion to other methods (to_raw_virtual and to_raw_real). This suggests that the actual signal handling logic is encapsulated within these methods.

To ensure that all required signals are supported, we need to verify the implementations of the to_raw_virtual and to_raw_real methods. Let's extract the details of these methods to confirm their completeness.


The absence of output from the ast-grep commands suggests that the to_raw_virtual and to_raw_real methods might not be directly implemented in the files we searched. They could be defined elsewhere or implemented differently.

To proceed, we should search for the definitions of these methods across the entire codebase to ensure we capture their implementations accurately.


The to_raw_virtual and to_raw_real methods are defined in yash-env/src/system/virtual/signal.rs and yash-env/src/system/real/signal.rs, respectively. To ensure that all required signals are supported, we need to extract the implementation details of these methods.


The absence of output from the ast-grep commands suggests that the methods to_raw_virtual and to_raw_real might be implemented differently or might not match the exact pattern we used. To ensure we capture their implementations accurately, we should search for the method bodies using rg to locate the exact lines and then extract the surrounding context.


The extracted context for the to_raw_virtual and to_raw_real methods shows that they handle various signal names and convert them to their corresponding signal numbers. The to_raw_virtual method supports a range of real-time signals, while the to_raw_real method maps specific signal names to their raw numbers using the nix::libc constants.

Based on this information, it appears that the system does support the required signals through these methods. Therefore, the concern about ensuring that the system supports all required signals is addressed.

  • to_raw_virtual method in yash-env/src/system/virtual/signal.rs handles a range of real-time signals.
  • to_raw_real method in yash-env/src/system/real/signal.rs maps specific signal names to their raw numbers.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all required signals are supported by the system.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type rust $'fn signal_number_from_name'

Length of output: 819



Script:

#!/bin/bash
# Extract the implementation details of the `signal_number_from_name` function from the identified files.

# Extract from yash-env/src/trap.rs
ast-grep --lang rust --pattern $'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> {
  $$$
}' yash-env/src/trap.rs

# Extract from yash-env/src/system.rs
ast-grep --lang rust --pattern $'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> {
  $$$
}' yash-env/src/system.rs

# Extract from yash-env/src/system/virtual.rs
ast-grep --lang rust --pattern $'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> {
  $$$
}' yash-env/src/system/virtual.rs

# Extract from yash-env/src/system/real.rs
ast-grep --lang rust --pattern $'fn signal_number_from_name(&self, name: signal::Name) -> Option<signal::Number> {
  $$$
}' yash-env/src/system/real.rs

Length of output: 1740



Script:

#!/bin/bash
# Extract the implementation details of the `to_raw_virtual` and `to_raw_real` methods.

# Extract `to_raw_virtual` method
ast-grep --lang rust --pattern $'fn to_raw_virtual(&self) -> Option<signal::Number> {
  $$$
}' yash-env/src/system/virtual.rs

# Extract `to_raw_real` method
ast-grep --lang rust --pattern $'fn to_raw_real(&self) -> Option<signal::Number> {
  $$$
}' yash-env/src/system/real.rs

Length of output: 247



Script:

#!/bin/bash
# Search for the definitions of the `to_raw_virtual` and `to_raw_real` methods across the entire codebase.

# Search for `to_raw_virtual` method
rg --type rust 'fn to_raw_virtual'

# Search for `to_raw_real` method
rg --type rust 'fn to_raw_real'

Length of output: 258



Script:

#!/bin/bash
# Extract the implementation details of the `to_raw_virtual` and `to_raw_real` methods.

# Extract `to_raw_virtual` method
ast-grep --lang rust --pattern $'fn to_raw_virtual(self) -> Option<Number> {
  $$$
}' yash-env/src/system/virtual/signal.rs

# Extract `to_raw_real` method
ast-grep --lang rust --pattern $'fn to_raw_real(self) -> Option<Number> {
  $$$
}' yash-env/src/system/real/signal.rs

Length of output: 243



Script:

#!/bin/bash
# Search for the definitions and surrounding context of the `to_raw_virtual` and `to_raw_real` methods.

# Search for `to_raw_virtual` method with surrounding context
rg --context 10 'fn to_raw_virtual' yash-env/src/system/virtual/signal.rs

# Search for `to_raw_real` method with surrounding context
rg --context 10 'fn to_raw_real' yash-env/src/system/real/signal.rs

Length of output: 1608

yash-env/src/system.rs (8)

57-57: The import of nix::sys::signal::Signal is still necessary for handling SigSet in methods like tcsetpgrp_with_block as per the discussion in previous comments.


219-228: The new method validate_signal is well-implemented. It provides a clear and concise way to validate signal numbers, returning the most common name for a signal number if multiple names exist.


269-273: The sigaction method is correctly updated to use the new signal::Number type. This change aligns with the PR's goal to use the new signal handling types.


311-311: The kill method update to use Option<signal::Number> is appropriate and aligns with the new signal handling strategy.


673-698: The methods signal_name_from_number and signal_number_from_exit_status are well-implemented, providing robust functionality for signal handling. These methods are essential for the correct interpretation of signals and exit statuses.


643-665: The method tcsetpgrp_without_block uses the new signal_number_from_name to handle SIGTTOU. This is a critical update for safely changing the foreground process group. Ensure that SIGTTOU is correctly handled in all relevant scenarios.

Verification successful

The search results indicate that SIGTTOU is referenced and handled in multiple files, including job.rs, system.rs, trap.rs, signal.rs, subshell.rs, and state.rs. The handling of SIGTTOU appears to be consistent with the expected behavior, particularly in the context of changing the foreground process group and managing signal masks.

Key points of interest include:

  • system.rs: Functions like tcsetpgrp_with_block and tcsetpgrp_without_block handle SIGTTOU by blocking and unblocking the signal appropriately.
  • trap.rs and trap/state.rs: Various tests and functions ensure that SIGTTOU is set to Ignore or Default as needed.
  • job.rs: Updates the process state to stopped(SIGTTOU) in relevant scenarios.

Given the comprehensive handling and testing of SIGTTOU across these files, the implementation appears robust.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct handling of `SIGTTOU` in `tcsetpgrp_without_block`.

# Test: Check all scenarios where `SIGTTOU` should be handled. Expect: Correct behavior in all cases.
echo "Check all scenarios where `SIGTTOU` should be handled."

Length of output: 186



Script:

#!/bin/bash
# Description: Search for all instances where `SIGTTOU` is handled in the codebase.

# Find all occurrences of `SIGTTOU` in the codebase
rg 'SIGTTOU'

Length of output: 5592



Script:

#!/bin/bash
# Description: Extract and review relevant code snippets for `SIGTTOU` handling.

# Extract code snippets from files where `SIGTTOU` is referenced
rg -A 5 -B 5 'SIGTTOU' yash-env/src/job.rs yash-env/src/system.rs yash-env/src/trap.rs yash-env/src/signal.rs yash-env/src/subshell.rs yash-env/src/trap/state.rs

Length of output: 30447


229-234: The method signal_number_from_name correctly retrieves the signal number based on the signal name. Ensure that all signal names used in the system are supported to avoid returning None.


298-298: The method caught_signals is crucial for handling caught signals. It's important to ensure that signals are not lost if they are caught when the list is full.

yash-env/src/trap.rs Show resolved Hide resolved
yash-env/src/trap.rs Show resolved Hide resolved
yash-env/src/trap.rs Show resolved Hide resolved
yash-env/src/trap.rs Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2e4f8b9 and 4ae6a2c.

Files selected for processing (1)
  • yash-builtin/src/kill/syntax.rs (24 hunks)
Additional context used
Learnings (1)
yash-builtin/src/kill/syntax.rs (2)
User: magicant
PR: magicant/yash-rs#367
File: yash-env/src/system.rs:57-57
Timestamp: 2024-06-08T02:51:51.839Z
Learning: The `yash-env/src/subshell.rs` module depends on `SigSet`, which requires `nix::sys::signal::Signal`. Plans are in place to remove `SigSet` in a future PR, and some existing methods like `tcsetpgrp_with_block` still depend on `nix::sys::signal::Signal`.
User: magicant
PR: magicant/yash-rs#367
File: yash-env/src/subshell.rs:40-40
Timestamp: 2024-06-08T02:49:23.406Z
Learning: The `yash-env/src/subshell.rs` module depends on `SigSet`, which requires `nix::sys::signal::Signal`. Plans are in place to remove `SigSet` in a future PR.
Additional comments not posted (7)
yash-builtin/src/kill/syntax.rs (7)

25-25: Import of Signal type aligns with the PR's objective to use the new signal handling system.


28-28: Import of yash_env::signal is necessary for the new signal handling logic.


359-395: Updated tests to reflect changes in signal parsing logic.

These updates are necessary to ensure that the new signal handling logic is correctly implemented and behaves as expected.


597-604: The test for option -l with operands has been updated to use the new signal types.

This change ensures that the tests are aligned with the new signal handling logic.


Line range hint 792-822: Added tests for invalid signal arguments, ensuring robust error handling.

These tests are crucial for verifying that the error handling logic correctly identifies invalid signals, enhancing the robustness of the command parsing.


193-195: Updated set_signal and parse_signals functions to work with the new Signal type.

These changes are crucial for integrating the new signal handling system. Verify that these functions are used consistently across the codebase to maintain uniformity in signal handling.

Also applies to: 222-225

Verification successful

The search results indicate that the set_signal and parse_signals functions are defined and used within the yash-builtin/src/kill/syntax.rs file. There are no other instances of these functions being used outside this file within the yash-builtin directory. This suggests that the changes to these functions are localized and do not impact other parts of the codebase.

  • set_signal is defined and used three times within yash-builtin/src/kill/syntax.rs.
  • parse_signals is defined and used once within yash-builtin/src/kill/syntax.rs.

Given this information, it appears that the functions are used consistently within the file where they are defined.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistent usage of `set_signal` and `parse_signals` across the codebase.

# Test: Search for the function usage. Expect: Consistent usage of the new signal handling logic.
rg --type rust $'set_signal|parse_signals'

Length of output: 4096



Script:

#!/bin/bash
# Description: Verify consistent usage of `set_signal` and `parse_signals` functions within the yash-builtin directory.

# Test: Search for the specific usage of `set_signal` and `parse_signals` functions.
rg --type rust 'set_signal|parse_signals' yash-builtin/

Length of output: 570


Line range hint 256-349: Significant refactoring in the parse function to accommodate the new signal handling logic.

This refactoring is extensive and touches many aspects of command parsing. It's crucial to ensure that all edge cases are handled correctly, especially with the new signal types.

Verification successful

The search results indicate that there are indeed tests for the parse_signal function in yash-builtin/src/kill/syntax.rs. These tests cover various scenarios, including valid signal names, signal numbers, and invalid inputs.

  • parse_signal("INT", false)
  • parse_signal("RtMin+5", false)
  • parse_signal("SigRtMin+5", false)
  • parse_signal("0", false)
  • parse_signal("1", false)
  • parse_signal("TERM1", false)
  • parse_signal("", false)

These tests suggest that edge cases are being handled, such as:

  • Valid signal names with and without the "SIG" prefix.
  • Valid signal numbers.
  • Invalid signal names and numbers.
  • Empty strings.

Given this information, it appears that the edge cases for signal parsing are adequately covered by the existing tests.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all edge cases in signal parsing are handled correctly.

# Test: Search for tests covering edge cases in signal parsing.
rg --type rust $'parse_signal|parse'

Length of output: 228275



Script:

#!/bin/bash
# Description: Verify that all edge cases in signal parsing are handled correctly by searching for specific test cases.

# Test: Search for test cases related to signal parsing in the test files.
rg --type rust --glob '*test*' 'parse_signal\(|parse\('

Length of output: 475



Script:

#!/bin/bash
# Description: Verify that all edge cases in signal parsing are handled correctly by searching for specific test cases.

# Test: Search for test cases specifically related to `parse_signal` and signal parsing in test files.
rg --type rust --glob '*test*' 'parse_signal\('

Length of output: 49



Script:

#!/bin/bash
# Description: Verify that all edge cases in signal parsing are handled correctly by searching for specific test cases.

# Test: Search for test cases related to signal parsing across all files.
rg --type rust 'parse_signal\('

Length of output: 2043

yash-builtin/src/kill/syntax.rs Show resolved Hide resolved
@magicant magicant merged commit c47a029 into master Jun 8, 2024
6 checks passed
@magicant magicant deleted the signal-types branch June 8, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant