Make hup_background_jobs accept the job list directly

This commit is contained in:
ridiculousfish
2020-02-19 20:35:04 -07:00
parent 59c6663a16
commit 05b8d4de97
4 changed files with 9 additions and 13 deletions

View File

@@ -903,7 +903,7 @@ static bool allow_exec_with_background_jobs(parser_t &parser) {
last_exec_run_count = current_run_count; last_exec_run_count = current_run_count;
return false; return false;
} else { } else {
hup_background_jobs(parser); hup_jobs(parser.jobs());
return true; return true;
} }
} }

View File

@@ -998,15 +998,10 @@ void proc_wait_any(parser_t &parser) {
process_clean_after_marking(parser, parser.libdata().is_interactive); process_clean_after_marking(parser, parser.libdata().is_interactive);
} }
void hup_background_jobs(const parser_t &parser) { void hup_jobs(const job_list_t &jobs) {
// TODO: we should probably hup all jobs across all parsers here. pid_t fish_pgrp = getpgrp();
for (const auto &j : parser.jobs()) { for (const auto &j : jobs) {
// Make sure we don't try to SIGHUP the calling builtin if (j->pgid != INVALID_PID && j->pgid != fish_pgrp && !j->is_completed()) {
if (j->pgid == INVALID_PID || !j->wants_job_control()) {
continue;
}
if (!j->is_completed()) {
if (j->is_stopped()) { if (j->is_stopped()) {
j->signal(SIGCONT); j->signal(SIGCONT);
} }

View File

@@ -591,8 +591,8 @@ void proc_wait_any(parser_t &parser);
void set_is_within_fish_initialization(bool flag); void set_is_within_fish_initialization(bool flag);
bool is_within_fish_initialization(); bool is_within_fish_initialization();
/// Terminate all background jobs /// Send SIGHUP to the list \p jobs, excepting those which are in fish's pgroup.
void hup_background_jobs(const parser_t &parser); void hup_jobs(const job_list_t &jobs);
/// Give ownership of the terminal to the specified job, if it wants it. /// Give ownership of the terminal to the specified job, if it wants it.
/// ///

View File

@@ -2365,6 +2365,7 @@ static void handle_end_loop(const parser_t &parser) {
} }
} }
// Perhaps print a warning before exiting.
reader_data_t *data = current_data(); reader_data_t *data = current_data();
auto bg_jobs = jobs_requiring_warning_on_exit(parser); auto bg_jobs = jobs_requiring_warning_on_exit(parser);
if (!data->prev_end_loop && !bg_jobs.empty()) { if (!data->prev_end_loop && !bg_jobs.empty()) {
@@ -2376,7 +2377,7 @@ static void handle_end_loop(const parser_t &parser) {
} }
// Kill remaining jobs before exiting. // Kill remaining jobs before exiting.
hup_background_jobs(parser); hup_jobs(parser.jobs());
} }
static bool selection_is_at_top() { static bool selection_is_at_top() {