diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-06 13:48:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-06 13:48:45 +0200 |
commit | 5bce0193de49a23a8b8409377859ddac546ec6c6 (patch) | |
tree | aa74c9432fdc012bf50119620b69d82ad86a7338 | |
parent | bf2cd9374cbaa8e4bbfdb1804255fa68fb23cd46 (diff) | |
download | serenity-5bce0193de49a23a8b8409377859ddac546ec6c6.zip |
Shell: Make Job constructors private and use a create() helper
Also store PGIDs as pid_t since that's what they are.
-rw-r--r-- | Shell/Job.h | 28 | ||||
-rw-r--r-- | Shell/Shell.cpp | 2 |
2 files changed, 14 insertions, 16 deletions
diff --git a/Shell/Job.h b/Shell/Job.h index 3275ddb803..945a4a7afe 100644 --- a/Shell/Job.h +++ b/Shell/Job.h @@ -42,9 +42,7 @@ class Job : public RefCounted<Job> { public: - explicit Job() - { - } + static NonnullRefPtr<Job> create(pid_t pid, pid_t pgid, String command, u64 job_id) { return adopt(*new Job(pid, pgid, move(command), job_id)); } ~Job() { @@ -56,17 +54,7 @@ public: #endif } - Job(pid_t pid, unsigned pgid, String cmd, u64 job_id) - : m_pgid(pgid) - , m_pid(pid) - , m_job_id(job_id) - , m_cmd(move(cmd)) - { - set_running_in_background(false); - m_command_timer.start(); - } - - unsigned pgid() const { return m_pgid; } + pid_t pgid() const { return m_pgid; } pid_t pid() const { return m_pid; } const String& cmd() const { return m_cmd; } u64 job_id() const { return m_job_id; } @@ -105,7 +93,17 @@ public: void deactivate() const { m_active = false; } private: - unsigned m_pgid { 0 }; + Job(pid_t pid, unsigned pgid, String cmd, u64 job_id) + : m_pgid(pgid) + , m_pid(pid) + , m_job_id(job_id) + , m_cmd(move(cmd)) + { + set_running_in_background(false); + m_command_timer.start(); + } + + pid_t m_pgid { 0 }; pid_t m_pid { 0 }; u64 m_job_id { 0 }; String m_cmd; diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index b4e8ee0d40..ddfad4d600 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -572,7 +572,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command) StringBuilder cmd; cmd.join(" ", command.argv); - auto job = adopt(*new Job(child, (unsigned)child, cmd.build(), find_last_job_id() + 1)); + auto job = Job::create(child, (unsigned)child, cmd.build(), find_last_job_id() + 1); jobs.set((u64)child, job); job->on_exit = [](auto job) { |