diff --git a/src/exec.cpp b/src/exec.cpp index a9f619019..f776dde1d 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -903,7 +903,7 @@ static bool allow_exec_with_background_jobs(parser_t &parser) { last_exec_run_count = current_run_count; return false; } else { - hup_background_jobs(parser); + hup_jobs(parser.jobs()); return true; } } diff --git a/src/proc.cpp b/src/proc.cpp index 081002849..a74584aba 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -998,15 +998,10 @@ void proc_wait_any(parser_t &parser) { process_clean_after_marking(parser, parser.libdata().is_interactive); } -void hup_background_jobs(const parser_t &parser) { - // TODO: we should probably hup all jobs across all parsers here. - for (const auto &j : parser.jobs()) { - // Make sure we don't try to SIGHUP the calling builtin - if (j->pgid == INVALID_PID || !j->wants_job_control()) { - continue; - } - - if (!j->is_completed()) { +void hup_jobs(const job_list_t &jobs) { + pid_t fish_pgrp = getpgrp(); + for (const auto &j : jobs) { + if (j->pgid != INVALID_PID && j->pgid != fish_pgrp && !j->is_completed()) { if (j->is_stopped()) { j->signal(SIGCONT); } diff --git a/src/proc.h b/src/proc.h index 305e9ef9d..3a4a7395b 100644 --- a/src/proc.h +++ b/src/proc.h @@ -591,8 +591,8 @@ void proc_wait_any(parser_t &parser); void set_is_within_fish_initialization(bool flag); bool is_within_fish_initialization(); -/// Terminate all background jobs -void hup_background_jobs(const parser_t &parser); +/// Send SIGHUP to the list \p jobs, excepting those which are in fish's pgroup. +void hup_jobs(const job_list_t &jobs); /// Give ownership of the terminal to the specified job, if it wants it. /// diff --git a/src/reader.cpp b/src/reader.cpp index 5ce39e6a5..b06abb0c5 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -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(); auto bg_jobs = jobs_requiring_warning_on_exit(parser); 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. - hup_background_jobs(parser); + hup_jobs(parser.jobs()); } static bool selection_is_at_top() {