mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
Shell: Do not attempt to yank the TTY from background processes
They don't own the TTY anyway!
This commit is contained in:
parent
217eca3d3f
commit
cf18bff72a
2 changed files with 15 additions and 8 deletions
|
@ -76,6 +76,7 @@ public:
|
||||||
bool should_be_disowned() const { return m_should_be_disowned; }
|
bool should_be_disowned() const { return m_should_be_disowned; }
|
||||||
void disown() { m_should_be_disowned = true; }
|
void disown() { m_should_be_disowned = true; }
|
||||||
bool is_running_in_background() const { return m_running_in_background; }
|
bool is_running_in_background() const { return m_running_in_background; }
|
||||||
|
bool should_announce_exit() const { return m_should_announce_exit; }
|
||||||
bool is_suspended() const { return m_is_suspended; }
|
bool is_suspended() const { return m_is_suspended; }
|
||||||
void unblock() const
|
void unblock() const
|
||||||
{
|
{
|
||||||
|
@ -113,6 +114,8 @@ public:
|
||||||
m_running_in_background = running_in_background;
|
m_running_in_background = running_in_background;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_should_announce_exit(bool value) { m_should_announce_exit = value; }
|
||||||
|
|
||||||
void deactivate() const { m_active = false; }
|
void deactivate() const { m_active = false; }
|
||||||
|
|
||||||
enum class PrintStatusMode {
|
enum class PrintStatusMode {
|
||||||
|
@ -143,6 +146,7 @@ private:
|
||||||
String m_cmd;
|
String m_cmd;
|
||||||
bool m_exited { false };
|
bool m_exited { false };
|
||||||
bool m_running_in_background { false };
|
bool m_running_in_background { false };
|
||||||
|
bool m_should_announce_exit { false };
|
||||||
int m_exit_code { -1 };
|
int m_exit_code { -1 };
|
||||||
int m_term_sig { -1 };
|
int m_term_sig { -1 };
|
||||||
Core::ElapsedTimer m_command_timer;
|
Core::ElapsedTimer m_command_timer;
|
||||||
|
|
|
@ -626,7 +626,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
job->on_exit = [](auto job) {
|
job->on_exit = [](auto job) {
|
||||||
if (!job->exited())
|
if (!job->exited())
|
||||||
return;
|
return;
|
||||||
if (job->is_running_in_background())
|
if (job->is_running_in_background() && job->should_announce_exit())
|
||||||
fprintf(stderr, "Shell: Job %" PRIu64 "(%s) exited\n", job->job_id(), job->cmd().characters());
|
fprintf(stderr, "Shell: Job %" PRIu64 "(%s) exited\n", job->job_id(), job->cmd().characters());
|
||||||
job->disown();
|
job->disown();
|
||||||
};
|
};
|
||||||
|
@ -670,10 +670,10 @@ NonnullRefPtrVector<Job> Shell::run_commands(Vector<AST::Command>& commands)
|
||||||
jobs_to_wait_for.append(*job);
|
jobs_to_wait_for.append(*job);
|
||||||
} else {
|
} else {
|
||||||
if (command.is_pipe_source) {
|
if (command.is_pipe_source) {
|
||||||
|
job->set_running_in_background(true);
|
||||||
jobs_to_wait_for.append(*job);
|
jobs_to_wait_for.append(*job);
|
||||||
} else if (command.should_notify_if_in_background) {
|
} else if (command.should_notify_if_in_background) {
|
||||||
job->set_running_in_background(true);
|
job->set_should_announce_exit(true);
|
||||||
restore_ios();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -710,23 +710,26 @@ void Shell::block_on_job(RefPtr<Job> job)
|
||||||
if (!job)
|
if (!job)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ScopeGuard io_restorer { [&]() {
|
||||||
|
if (job->exited() && !job->is_running_in_background()) {
|
||||||
|
restore_ios();
|
||||||
|
}
|
||||||
|
} };
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
job->on_exit = [&, old_exit = move(job->on_exit)](auto job) {
|
job->on_exit = [&, old_exit = move(job->on_exit)](auto job) {
|
||||||
if (old_exit)
|
if (old_exit)
|
||||||
old_exit(job);
|
old_exit(job);
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
};
|
};
|
||||||
if (job->exited()) {
|
|
||||||
restore_ios();
|
if (job->exited())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
if (job->is_suspended())
|
if (job->is_suspended())
|
||||||
job->print_status(Job::PrintStatusMode::Basic);
|
job->print_status(Job::PrintStatusMode::Basic);
|
||||||
|
|
||||||
restore_ios();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String Shell::get_history_path()
|
String Shell::get_history_path()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue