1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-08 17:37:35 +00:00

Shell: Keep the TTY on the same pgroup to get tty signals

This allows the shell to be notified about SIGWINCH even when a child
process is running in the foreground.
This commit is contained in:
AnotherTest 2020-07-06 20:33:08 +04:30 committed by Andreas Kling
parent 5fedf90bf9
commit 5cdb0ef2e5
4 changed files with 19 additions and 9 deletions

View file

@ -435,8 +435,6 @@ RefPtr<Job> Shell::run_command(AST::Command& command)
return nullptr;
}
if (child == 0) {
setpgid(0, 0);
tcsetpgrp(0, getpid());
tcsetattr(0, TCSANOW, &default_termios);
for (auto& rewiring : rewirings) {
#ifdef SH_DEBUG
@ -511,14 +509,16 @@ bool Shell::run_file(const String& filename, bool explicitly_invoked)
run_command(data);
return true;
}
void Shell::take_back_stdin()
void Shell::restore_stdin()
{
tcsetpgrp(0, m_pid);
tcsetattr(0, TCSANOW, &termios);
}
void Shell::block_on_job(RefPtr<Job> job)
{
ScopedValueRollback accepting_signal_rollback(m_is_accepting_signals);
m_is_accepting_signals = false;
if (!job)
return;
@ -529,13 +529,13 @@ void Shell::block_on_job(RefPtr<Job> job)
loop.quit(0);
};
if (job->exited()) {
take_back_stdin();
restore_stdin();
return;
}
loop.exec();
take_back_stdin();
restore_stdin();
}
String Shell::get_history_path()
@ -872,7 +872,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_option(const String& program_
bool Shell::read_single_line()
{
take_back_stdin();
restore_stdin();
auto line_result = editor->get_line(prompt());
if (line_result.is_error()) {