mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
Shell: Avoid messing with sigaction while waiting for a child
This commit is contained in:
parent
70a213a6ec
commit
d5e9213683
3 changed files with 10 additions and 11 deletions
|
@ -1024,21 +1024,15 @@ ContinuationRequest Shell::is_complete(const Vector<Command>& commands)
|
|||
|
||||
IterationDecision Shell::wait_for_pid(const Shell::SpawnedProcess& process, bool is_first_command_in_chain, int& return_value)
|
||||
{
|
||||
// Disable signal handler for the first command, as we actively wait for it
|
||||
sighandler_t chld_handler = nullptr;
|
||||
if (is_first_command_in_chain) {
|
||||
chld_handler = signal(SIGCHLD, nullptr);
|
||||
dbg() << "Waiting for " << process.name;
|
||||
}
|
||||
if (is_first_command_in_chain)
|
||||
m_waiting_for_pid = process.pid;
|
||||
|
||||
int wstatus = 0;
|
||||
int rc = waitpid(process.pid, &wstatus, WSTOPPED);
|
||||
auto errno_save = errno;
|
||||
|
||||
if (is_first_command_in_chain) {
|
||||
signal(SIGCHLD, chld_handler);
|
||||
dbg() << process.name << " is probably dead now (" << rc << ", " << strerror(errno_save) << ") -> exited " << WIFEXITED(wstatus) << " stopped " << WIFSTOPPED(wstatus);
|
||||
}
|
||||
if (is_first_command_in_chain)
|
||||
m_waiting_for_pid = -1;
|
||||
|
||||
errno = errno_save;
|
||||
if (rc < 0 && errno != EINTR) {
|
||||
|
|
|
@ -115,6 +115,8 @@ public:
|
|||
void highlight(Line::Editor&) const;
|
||||
Vector<Line::CompletionSuggestion> complete(const Line::Editor&);
|
||||
|
||||
bool is_waiting_for(pid_t pid) const { return m_waiting_for_pid == pid; }
|
||||
|
||||
String get_history_path();
|
||||
void load_history();
|
||||
void save_history();
|
||||
|
@ -187,6 +189,7 @@ private:
|
|||
StringBuilder m_complete_line_builder;
|
||||
bool m_should_break_current_command { false };
|
||||
bool m_should_ignore_jobs_on_next_exit { false };
|
||||
pid_t m_waiting_for_pid { -1 };
|
||||
};
|
||||
|
||||
static constexpr bool is_word_character(char c)
|
||||
|
|
|
@ -74,6 +74,8 @@ int main(int argc, char** argv)
|
|||
signal(SIGCHLD, [](int) {
|
||||
auto& jobs = s_shell->jobs;
|
||||
for (auto& job : jobs) {
|
||||
if (s_shell->is_waiting_for(job.value->pid()))
|
||||
continue;
|
||||
int wstatus = 0;
|
||||
auto child_pid = waitpid(job.value->pid(), &wstatus, WNOHANG);
|
||||
if (child_pid == job.value->pid()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue