mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Shell: Warn the user about active jobs on exit
And make sure that the user means to exit and kill current jobs before exiting.
This commit is contained in:
parent
c23c354779
commit
b4ca563637
Notes:
sideshowbarker
2024-07-19 06:09:50 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/b4ca5636377 Pull-request: https://github.com/SerenityOS/serenity/pull/2361 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bugaevc
2 changed files with 12 additions and 0 deletions
|
@ -337,6 +337,13 @@ int Shell::builtin_dirs(int argc, const char** argv)
|
|||
|
||||
int Shell::builtin_exit(int, const char**)
|
||||
{
|
||||
if (!jobs.is_empty()) {
|
||||
if (!m_should_ignore_jobs_on_next_exit) {
|
||||
printf("Shell: Hey dude, you have %zu active job%s, run 'exit' again to really exit.\n", jobs.size(), jobs.size() > 1 ? "s" : "");
|
||||
m_should_ignore_jobs_on_next_exit = true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
stop_all_jobs();
|
||||
printf("Good-bye!\n");
|
||||
exit(0);
|
||||
|
@ -1355,6 +1362,10 @@ ExitCodeOrContinuationRequest Shell::run_command(const StringView& cmd)
|
|||
// Is the terminal controlling pgrp really still the PGID of the dead process?
|
||||
tcsetpgrp(0, getpid());
|
||||
tcsetattr(0, TCSANOW, &trm);
|
||||
|
||||
// Clear the exit flag after any non-exit command has been executed.
|
||||
m_should_ignore_jobs_on_next_exit = false;
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
|
|
@ -186,6 +186,7 @@ private:
|
|||
ExitCodeOrContinuationRequest::ContinuationRequest m_should_continue { ExitCodeOrContinuationRequest::Nothing };
|
||||
StringBuilder m_complete_line_builder;
|
||||
bool m_should_break_current_command { false };
|
||||
bool m_should_ignore_jobs_on_next_exit { false };
|
||||
};
|
||||
|
||||
static constexpr bool is_word_character(char c)
|
||||
|
|
Loading…
Reference in a new issue