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:
AnotherTest 2020-05-25 02:32:41 +04:30 committed by Andreas Kling
parent c23c354779
commit b4ca563637
Notes: sideshowbarker 2024-07-19 06:09:50 +09:00
2 changed files with 12 additions and 0 deletions

View file

@ -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;
}

View file

@ -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)