From 9b1e04dba2802576efd8c9bc2fca9370b7ecf659 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 3 Nov 2021 10:24:49 -0700 Subject: [PATCH] Use a real flag to mark that a process has generated an exit event Exited processes generate event_t::process_exit if they exit with a nonzero status. Prior to this change, to avoid sending duplicate events, we would clear the status. This is ugly since we're lying about the process exit status. Use a real flag to prevent sending duplicate notifications. --- src/proc.cpp | 7 ++----- src/proc.h | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index fa65e66ed..e2674d946 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -536,10 +536,10 @@ static void remove_disowned_jobs(job_list_t &jobs) { /// \return true if we printed a status message, false if not. static bool try_clean_process_in_job(parser_t &parser, process_t *p, job_t *j, std::vector *exit_events) { - if (!p->completed || !p->pid) { + if (p->marked_exit_event || !p->completed || !p->pid) { return false; } - + p->marked_exit_event = true; auto s = p->status; // Add an exit event if the process did not come from a job handler. @@ -573,9 +573,6 @@ static bool try_clean_process_in_job(parser_t &parser, process_t *p, job_t *j, args.push_back(p->argv0()); } call_job_summary(parser, args); - // Clear status so it is not reported more than once. - // TODO: this seems like a clumsy way to ensure that. - p->status = proc_status_t::from_exit_code(0); return true; } diff --git a/src/proc.h b/src/proc.h index cb0fe0894..f2cc1066f 100644 --- a/src/proc.h +++ b/src/proc.h @@ -278,6 +278,9 @@ class process_t : noncopyable_t { /// True if process has stopped. bool stopped{false}; + /// Set once we have generated (or decided not to generate) a process_exit event. + bool marked_exit_event{false}; + /// Reported status value. proc_status_t status{};