1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:15:07 +00:00

Shell: Store jobs as NonnullRefPtr<Job>

This commit is contained in:
Andreas Kling 2020-08-06 14:09:13 +02:00
parent 5bce0193de
commit b8440b12b7
2 changed files with 16 additions and 14 deletions

View file

@ -83,15 +83,17 @@ int main(int argc, char** argv)
Core::EventLoop::register_signal(SIGCHLD, [](int) {
auto& jobs = s_shell->jobs;
Vector<u64> disowned_jobs;
for (auto& job : jobs) {
for (auto& it : jobs) {
auto job_id = it.key;
auto& job = *it.value;
int wstatus = 0;
auto child_pid = waitpid(job.value->pid(), &wstatus, WNOHANG | WUNTRACED);
auto child_pid = waitpid(job.pid(), &wstatus, WNOHANG | WUNTRACED);
if (child_pid < 0) {
if (errno == ECHILD) {
// The child process went away before we could process its death, just assume it exited all ok.
// FIXME: This should never happen, the child should stay around until we do the waitpid above.
dbg() << "Child process gone, cannot get exit code for " << job.key;
child_pid = job.value->pid();
dbg() << "Child process gone, cannot get exit code for " << job_id;
child_pid = job.pid();
} else {
ASSERT_NOT_REACHED();
}
@ -102,21 +104,21 @@ int main(int argc, char** argv)
continue;
}
#endif
if (child_pid == job.value->pid()) {
if (child_pid == job.pid()) {
if (WIFEXITED(wstatus)) {
job.value->set_has_exit(WEXITSTATUS(wstatus));
job.set_has_exit(WEXITSTATUS(wstatus));
} else if (WIFSIGNALED(wstatus) && !WIFSTOPPED(wstatus)) {
job.value->set_has_exit(126);
job.set_has_exit(126);
} else if (WIFSTOPPED(wstatus)) {
job.value->unblock();
job.value->set_is_suspended(true);
job.unblock();
job.set_is_suspended(true);
}
}
if (job.value->should_be_disowned())
disowned_jobs.append(job.key);
if (job.should_be_disowned())
disowned_jobs.append(job_id);
}
for (auto key : disowned_jobs)
jobs.remove(key);
for (auto job_id : disowned_jobs)
jobs.remove(job_id);
});
Core::EventLoop::register_signal(SIGTSTP, [](auto) {