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

feat(exit): suspended jobs warning and sending kill signals #287

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

John-Bush14
Copy link

exit warns user if user has suspended jobs running and sends SIGHUP's on second try.

@John-Bush14
Copy link
Author

sorry mistake 😅

@reubeno
Copy link
Owner

reubeno commented Dec 6, 2024

Thanks for your contribution, @John-Bush14 ! It's great to see progress on this feature. Please don't hesitate to reach out here or in the Discussions area of the project if you have any questions along the process. I've also enabled the checks to start running, so you may find some new results that will need to be looked at.

We'll aim to review the changes in detail over the weekend or early next week.

@reubeno reubeno added the needs_review PR or issue author is waiting for a review label Dec 7, 2024
Copy link
Owner

@reubeno reubeno left a comment

Choose a reason for hiding this comment

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

Thanks for putting these changes together! It's quite helpful that you were willing to pick up one of our active issues.

The code looks relatively straightforward; I've left a few questions and comments after a more detailed review. Don't hesitate to ask questions here if you have any.

@@ -42,6 +42,9 @@ pub struct Shell {
// Additional state
/// The status of the last completed command.
pub last_exit_status: u8,

/// User tried exiting in the previous/current input if != 0.
pub user_tried_exiting: u8,
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a reason for this to be an integer instead of a simple bool flag? Are there cases in which you think we'd need to track how many times the user tried exiting?

@@ -408,9 +408,9 @@ impl Job {
}

/// Kills the job.
pub fn kill(&mut self) -> Result<(), error::Error> {
pub fn kill(&mut self, signal: Option<nix::sys::signal::Signal>) -> Result<(), error::Error> {
Copy link
Owner

Choose a reason for hiding this comment

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

You may run into challenges exposing a nix type in this function--I recall it being used in non-Unix platforms (e.g., Windows). An alternative approach might be to define a separate abstract enum type for signals we can send to jobs. It might require adding some new functions under the sys module too.

@@ -14,6 +16,18 @@ impl builtins::Command for ExitCommand {
&self,
context: commands::ExecutionContext<'_>,
) -> Result<crate::builtins::ExitCode, crate::error::Error> {
if !context.shell.jobs.jobs.is_empty() && context.shell.user_tried_exiting == 0 {
writeln!(context.stdout(), "brush: You have suspended jobs.")?;
Copy link
Owner

Choose a reason for hiding this comment

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

Minor code note: would be nice to avoid hard-coding the display name of the shell. If I recall correctly Shell::shell_name can be used.

@@ -1,5 +1,7 @@
use clap::Parser;

use std::io::Write;
Copy link
Owner

Choose a reason for hiding this comment

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

Right now, a Ctrl+D based exit won't actually invoke the exit built-in. Do we need to make an additional change to make sure that path also works in the same way?

@reubeno reubeno added updates_requested Pull requests with updates requested and removed needs_review PR or issue author is waiting for a review labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
updates_requested Pull requests with updates requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants