Rationalize background-in-background procs

If a background process runs a fish function which launches another
background process, ensure that these background procs get different
pgroups. Add a test for it.
This commit is contained in:
ridiculousfish 2020-02-20 12:18:36 -07:00
parent 24bd7e033e
commit c5fa580948
2 changed files with 15 additions and 2 deletions

View File

@ -59,9 +59,10 @@ pgroup_provenance_t get_pgroup_provenance(const shared_ptr<job_t> &j,
bool has_external = j->has_external_proc();
assert(first_proc_is_internal ? has_internal : has_external);
if (lineage.parent_pgid.has_value()) {
if (lineage.parent_pgid.has_value() && j->is_foreground()) {
// Our lineage indicates a pgid. This means the job is "nested" as a function or block
// inside another job, which has a real pgroup. We're going to use that.
// inside another job, which has a real pgroup. We're going to use that, unless it's
// backgrounded, in which case it should not inherit a pgroup.
return pgroup_provenance_t::lineage;
} else if (!j->wants_job_control()) {
// This job doesn't need job control, it can just live in the fish pgroup.

View File

@ -35,3 +35,15 @@ end
and echo "All pgroups agreed"
or echo "Pgroups disagreed. Found $a0 $a1 $a2, and $b0 $b1 $b2"
# CHECK: All pgroups agreed
# Ensure that if a background job launches another background job, that they have different pgroups.
# The pipeline here will arrange for the two pgroups to be printed on the same line, like:
# 123 124
# Our regex will capture the first pgroup and use a negative lookahead on the second.
status job-control full
$fth print_pgrp | begin
tr \n ' '
$fth print_pgrp &
end &
wait
# CHECK: {{(\d+) (?!\1)\d+}}