mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Shell: Never assign equal job ids to two different jobs
Since the last job need not have an ID of size()-1, we need to find the max job id and give that+1 out
This commit is contained in:
parent
790915da54
commit
ce61cad933
Notes:
sideshowbarker
2024-07-19 06:05:17 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/ce61cad9338 Pull-request: https://github.com/SerenityOS/serenity/pull/2398 Reviewed-by: https://github.com/awesomekling
@ -154,8 +154,8 @@ int Shell::builtin_bg(int argc, const char** argv)
|
||||
if (!parser.parse(argc, const_cast<char**>(argv), false))
|
||||
return 1;
|
||||
|
||||
if (job_id == -1)
|
||||
job_id = jobs.size() - 1;
|
||||
if (job_id == -1 && !jobs.is_empty())
|
||||
job_id = find_last_job_id();
|
||||
|
||||
Job* job = nullptr;
|
||||
|
||||
@ -400,8 +400,8 @@ int Shell::builtin_fg(int argc, const char** argv)
|
||||
if (!parser.parse(argc, const_cast<char**>(argv), false))
|
||||
return 1;
|
||||
|
||||
if (job_id == -1)
|
||||
job_id = jobs.size() - 1;
|
||||
if (job_id == -1 && !jobs.is_empty())
|
||||
job_id = find_last_job_id();
|
||||
|
||||
Job* job = nullptr;
|
||||
|
||||
@ -1311,7 +1311,7 @@ ExitCodeOrContinuationRequest Shell::run_command(const StringView& cmd)
|
||||
StringBuilder cmd;
|
||||
cmd.join(" ", argv_string);
|
||||
|
||||
auto job = make<Job>(child, (unsigned)child, cmd.build(), jobs.size());
|
||||
auto job = make<Job>(child, (unsigned)child, cmd.build(), find_last_job_id() + 1);
|
||||
jobs.set((u64)child, move(job));
|
||||
}
|
||||
|
||||
@ -1836,6 +1836,16 @@ void Shell::stop_all_jobs()
|
||||
}
|
||||
}
|
||||
|
||||
u64 Shell::find_last_job_id() const
|
||||
{
|
||||
u64 job_id = 0;
|
||||
for (auto& entry : jobs) {
|
||||
if (entry.value->job_id() > job_id)
|
||||
job_id = entry.value->job_id();
|
||||
}
|
||||
return job_id;
|
||||
}
|
||||
|
||||
void Shell::save_to(JsonObject& object)
|
||||
{
|
||||
Core::Object::save_to(object);
|
||||
|
@ -117,6 +117,8 @@ public:
|
||||
|
||||
bool is_waiting_for(pid_t pid) const { return m_waiting_for_pid == pid; }
|
||||
|
||||
u64 find_last_job_id() const;
|
||||
|
||||
String get_history_path();
|
||||
void load_history();
|
||||
void save_history();
|
||||
|
Loading…
Reference in New Issue
Block a user