mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 00:08:11 +00:00
Shell: Make Job constructors private and use a create() helper
Also store PGIDs as pid_t since that's what they are.
This commit is contained in:
parent
bf2cd9374c
commit
5bce0193de
2 changed files with 14 additions and 16 deletions
28
Shell/Job.h
28
Shell/Job.h
|
@ -42,9 +42,7 @@
|
||||||
|
|
||||||
class Job : public RefCounted<Job> {
|
class Job : public RefCounted<Job> {
|
||||||
public:
|
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()
|
~Job()
|
||||||
{
|
{
|
||||||
|
@ -56,17 +54,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Job(pid_t pid, unsigned pgid, String cmd, u64 job_id)
|
pid_t pgid() const { return m_pgid; }
|
||||||
: 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 pid() const { return m_pid; }
|
pid_t pid() const { return m_pid; }
|
||||||
const String& cmd() const { return m_cmd; }
|
const String& cmd() const { return m_cmd; }
|
||||||
u64 job_id() const { return m_job_id; }
|
u64 job_id() const { return m_job_id; }
|
||||||
|
@ -105,7 +93,17 @@ public:
|
||||||
void deactivate() const { m_active = false; }
|
void deactivate() const { m_active = false; }
|
||||||
|
|
||||||
private:
|
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 };
|
pid_t m_pid { 0 };
|
||||||
u64 m_job_id { 0 };
|
u64 m_job_id { 0 };
|
||||||
String m_cmd;
|
String m_cmd;
|
||||||
|
|
|
@ -572,7 +572,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
||||||
StringBuilder cmd;
|
StringBuilder cmd;
|
||||||
cmd.join(" ", command.argv);
|
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);
|
jobs.set((u64)child, job);
|
||||||
|
|
||||||
job->on_exit = [](auto job) {
|
job->on_exit = [](auto job) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue