Clarify return value of job_reap and process_clean_after_marking

This commit is contained in:
ridiculousfish 2019-04-29 09:05:00 -07:00
parent 9700800ecf
commit b8170ec1ce
2 changed files with 13 additions and 13 deletions

View file

@ -460,9 +460,11 @@ void remove_disowned_jobs(job_list_t &jobs) {
} }
} }
/// Remove completed jobs from the job list, printing status messages as appropriate.
/// \return whether something was printed.
static bool process_clean_after_marking(bool allow_interactive) { static bool process_clean_after_marking(bool allow_interactive) {
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
bool found = false; bool printed = false;
// This function may fire an event handler, we do not want to call ourselves recursively (to // This function may fire an event handler, we do not want to call ourselves recursively (to
// avoid infinite recursion). // avoid infinite recursion).
@ -545,8 +547,8 @@ static bool process_clean_after_marking(bool allow_interactive) {
if (clr_eol) outputter_t::stdoutput().term_puts(clr_eol, 1); if (clr_eol) outputter_t::stdoutput().term_puts(clr_eol, 1);
std::fwprintf(stdout, L"\n"); std::fwprintf(stdout, L"\n");
printed = true;
} }
found = false;
// clear status so it is not reported more than once // clear status so it is not reported more than once
p->status = proc_status_t::from_exit_code(0); p->status = proc_status_t::from_exit_code(0);
} }
@ -557,7 +559,7 @@ static bool process_clean_after_marking(bool allow_interactive) {
if (!j->is_foreground() && !j->get_flag(job_flag_t::NOTIFIED) && if (!j->is_foreground() && !j->get_flag(job_flag_t::NOTIFIED) &&
!j->get_flag(job_flag_t::SKIP_NOTIFICATION)) { !j->get_flag(job_flag_t::SKIP_NOTIFICATION)) {
print_job_status(j.get(), JOB_ENDED); print_job_status(j.get(), JOB_ENDED);
found = true; printed = true;
} }
erase_list.push_back(j); erase_list.push_back(j);
@ -565,7 +567,7 @@ static bool process_clean_after_marking(bool allow_interactive) {
// Notify the user about newly stopped jobs. // Notify the user about newly stopped jobs.
if (!j->get_flag(job_flag_t::SKIP_NOTIFICATION)) { if (!j->get_flag(job_flag_t::SKIP_NOTIFICATION)) {
print_job_status(j.get(), JOB_STOPPED); print_job_status(j.get(), JOB_STOPPED);
found = true; printed = true;
} }
j->set_flag(job_flag_t::NOTIFIED, true); j->set_flag(job_flag_t::NOTIFIED, true);
} }
@ -604,29 +606,27 @@ static bool process_clean_after_marking(bool allow_interactive) {
erase_list.clear(); erase_list.clear();
if (found) { if (printed) {
fflush(stdout); fflush(stdout);
} }
locked = false; locked = false;
return found; return printed;
} }
bool job_reap(bool allow_interactive) { bool job_reap(bool allow_interactive) {
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
bool found = false;
process_mark_finished_children(false); process_mark_finished_children(false);
// Preserve the exit status. // Preserve the exit status.
auto saved_statuses = proc_get_last_statuses(); auto saved_statuses = proc_get_last_statuses();
found = process_clean_after_marking(allow_interactive); bool printed = process_clean_after_marking(allow_interactive);
// Restore the exit status. // Restore the exit status.
proc_set_last_statuses(std::move(saved_statuses)); proc_set_last_statuses(std::move(saved_statuses));
return found; return printed;
} }
/// Maximum length of a /proc/[PID]/stat filename. /// Maximum length of a /proc/[PID]/stat filename.

View file

@ -482,9 +482,9 @@ void proc_set_last_statuses(statuses_t s);
int proc_get_last_status(); int proc_get_last_status();
statuses_t proc_get_last_statuses(); statuses_t proc_get_last_statuses();
/// Notify the user about stopped or terminated jobs. Delete terminated jobs from the job list. /// Notify the user about stopped or terminated jobs, and delete completed jobs from the job list.
/// /// If \p interactive is set, allow reaping interactive jobs; otherwise skip them.
/// \param interactive whether interactive jobs should be reaped as well /// \return whether text was printed to stdout.
bool job_reap(bool interactive); bool job_reap(bool interactive);
/// Mark a process as failed to execute (and therefore completed). /// Mark a process as failed to execute (and therefore completed).