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.
This commit is contained in:
ridiculousfish 2021-11-03 10:24:49 -07:00
parent 7993987b23
commit 9b1e04dba2
2 changed files with 5 additions and 5 deletions

View File

@ -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<event_t> *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;
}

View File

@ -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{};