From 04a96f6c6e1ec585dc24f30c6330468ae0190aa0 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 10 Apr 2019 10:56:33 -0500 Subject: [PATCH] Change when PENDING_REMOVAL jobs are removed Followup to 394623b. Doing it in the parser meant only top-level jobs would be reaped after being `disown`ed, as subjobs aren't directly handled by the parser. This is also much cleaner, as now job removal is centralized in `process_clean_after_marking()`. Closes #5803. --- src/parse_execution.cpp | 5 ----- src/proc.cpp | 8 +++++++- src/proc.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 08ca4e658..06ed5bf00 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -1269,11 +1269,6 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo remove_job(job.get()); } - // This job was disowned during its own execution or the execution of its subjobs - if (job->get_flag(job_flag_t::PENDING_REMOVAL)) { - remove_job(job.get()); - } - // Only external commands require a new fishd barrier. if (job_contained_external_command) { set_proc_had_barrier(false); diff --git a/src/proc.cpp b/src/proc.cpp index 514459af0..c4777764b 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -542,9 +542,15 @@ static bool process_clean_after_marking(bool allow_interactive) { p->status = proc_status_t::from_exit_code(0); } + // If the process has been previously flagged for removal, add it to the erase list without + // any further processing, but do not remove any jobs until their parent jobs have completed + // processing. + if (j->get_flag(job_flag_t::PENDING_REMOVAL) && j->job_chain_is_fully_constructed()) { + erase_list.push_back(j); + } // If all processes have completed, tell the user the job has completed and delete it from // the active job list. - if (j->is_completed()) { + else if (j->is_completed()) { if (!j->is_foreground() && !j->get_flag(job_flag_t::NOTIFIED) && !j->get_flag(job_flag_t::SKIP_NOTIFICATION)) { print_job_status(j.get(), JOB_ENDED); diff --git a/src/proc.h b/src/proc.h index 3b6186799..c39e1a123 100644 --- a/src/proc.h +++ b/src/proc.h @@ -401,7 +401,7 @@ class job_t { /// The job is in a stopped state bool is_stopped() const; /// The job is OK to be externally visible, e.g. to the user via `jobs` - bool is_visible() const { return !is_completed() && is_constructed() && !get_flag(job_flag_t::PENDING_REMOVAL); }; + bool is_visible() const { return !is_completed() && is_constructed() && !get_flag(job_flag_t::PENDING_REMOVAL) && !parent_job; }; /// \return the parent job, or nullptr. const std::shared_ptr get_parent() const { return parent_job; }