1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

Shell: Stop a for loop upon receiving two consecutive interruptions

This does not work perfectly (just like every other shell...), if the
running program handles the signal (SIGINT in this case) and quits
cleanly, the shell cannot detect the interruption.
This is the case with our `sleep(1)`.
This commit is contained in:
AnotherTest 2020-08-08 13:48:07 +04:30 committed by Andreas Kling
parent c81c8b68bb
commit 5ae2f6e9ec
3 changed files with 38 additions and 4 deletions

View file

@ -59,7 +59,17 @@ public:
const String& cmd() const { return m_cmd; }
u64 job_id() const { return m_job_id; }
bool exited() const { return m_exited; }
int exit_code() const { return m_exit_code; }
bool signaled() const { return m_term_sig != -1; }
int exit_code() const
{
ASSERT(exited());
return m_exit_code;
}
int termination_signal() const
{
ASSERT(signaled());
return m_term_sig;
}
bool should_be_disowned() const { return m_should_be_disowned; }
void disown() { m_should_be_disowned = true; }
bool is_running_in_background() const { return m_running_in_background; }
@ -82,6 +92,16 @@ public:
if (on_exit)
on_exit(*this);
}
void set_signalled(int sig)
{
if (m_exited)
return;
m_exited = true;
m_exit_code = 126;
m_term_sig = sig;
if (on_exit)
on_exit(*this);
}
void set_is_suspended(bool value) const { m_is_suspended = value; }
@ -118,6 +138,7 @@ private:
bool m_exited { false };
bool m_running_in_background { false };
int m_exit_code { -1 };
int m_term_sig { -1 };
Core::ElapsedTimer m_command_timer;
mutable bool m_active { true };
mutable bool m_is_suspended { false };