summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-06 14:09:13 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-06 14:09:13 +0200
commitb8440b12b795a88ba2a2cca89a9ce7e77fa682c0 (patch)
tree1a6d436e643a6c48026c2b263c1eced289a6e8fd
parent5bce0193de49a23a8b8409377859ddac546ec6c6 (diff)
downloadserenity-b8440b12b795a88ba2a2cca89a9ce7e77fa682c0.zip
Shell: Store jobs as NonnullRefPtr<Job>
-rw-r--r--Shell/Shell.h2
-rw-r--r--Shell/main.cpp28
2 files changed, 16 insertions, 14 deletions
diff --git a/Shell/Shell.h b/Shell/Shell.h
index 3fceed2215..a04396e5df 100644
--- a/Shell/Shell.h
+++ b/Shell/Shell.h
@@ -165,7 +165,7 @@ public:
int last_return_code { 0 };
Vector<String> directory_stack;
CircularQueue<String, 8> cd_history; // FIXME: have a configurable cd history length
- HashMap<u64, RefPtr<Job>> jobs;
+ HashMap<u64, NonnullRefPtr<Job>> jobs;
Vector<String, 256> cached_path;
enum ShellEventType {
diff --git a/Shell/main.cpp b/Shell/main.cpp
index 9a6bea67bb..8434548e8d 100644
--- a/Shell/main.cpp
+++ b/Shell/main.cpp
@@ -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) {