mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-23 20:44:26 +08:00
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:
parent
24bd7e033e
commit
c5fa580948
@ -59,9 +59,10 @@ pgroup_provenance_t get_pgroup_provenance(const shared_ptr<job_t> &j,
|
|||||||
bool has_external = j->has_external_proc();
|
bool has_external = j->has_external_proc();
|
||||||
assert(first_proc_is_internal ? has_internal : has_external);
|
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
|
// 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;
|
return pgroup_provenance_t::lineage;
|
||||||
} else if (!j->wants_job_control()) {
|
} else if (!j->wants_job_control()) {
|
||||||
// This job doesn't need job control, it can just live in the fish pgroup.
|
// This job doesn't need job control, it can just live in the fish pgroup.
|
||||||
|
@ -35,3 +35,15 @@ end
|
|||||||
and echo "All pgroups agreed"
|
and echo "All pgroups agreed"
|
||||||
or echo "Pgroups disagreed. Found $a0 $a1 $a2, and $b0 $b1 $b2"
|
or echo "Pgroups disagreed. Found $a0 $a1 $a2, and $b0 $b1 $b2"
|
||||||
# CHECK: All pgroups agreed
|
# 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+}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user