2024-03-30 15:10:12 +00:00
|
|
|
# RUN: env fth=%fish_test_helper fish=%fish %fish %s | %filter-ctrlseqs
|
2019-12-08 21:28:30 +00:00
|
|
|
|
2020-03-02 22:01:59 +00:00
|
|
|
status job-control full
|
|
|
|
|
2019-12-08 21:28:30 +00:00
|
|
|
# Ensure that lots of nested jobs all end up in the same pgroup.
|
|
|
|
|
|
|
|
function save_pgroup -a var_name
|
|
|
|
$fth print_pgrp | read -g $var_name
|
|
|
|
end
|
|
|
|
|
|
|
|
# Here everything should live in the pgroup of the first fish_test_helper.
|
2020-01-13 19:34:22 +00:00
|
|
|
$fth print_pgrp | read -g global_group | save_pgroup g1 | begin
|
|
|
|
save_pgroup g2
|
2020-03-11 18:06:52 +00:00
|
|
|
end | begin
|
|
|
|
echo (save_pgroup g3) >/dev/null
|
2020-01-13 19:34:22 +00:00
|
|
|
end
|
2019-12-08 21:28:30 +00:00
|
|
|
|
2020-03-11 18:06:52 +00:00
|
|
|
[ "$global_group" -eq "$g1" ] && [ "$g1" -eq "$g2" ] && [ "$g2" -eq "$g3" ]
|
2019-12-08 21:28:30 +00:00
|
|
|
and echo "All pgroups agreed"
|
2020-03-11 18:06:52 +00:00
|
|
|
or echo "Pgroups disagreed. Should be in $global_group but found $g1, $g2, $g3"
|
2019-12-08 21:28:30 +00:00
|
|
|
# CHECK: All pgroups agreed
|
|
|
|
|
|
|
|
# Here everything should live in fish's pgroup.
|
|
|
|
# Unfortunately we don't know what fish's pgroup is (it may not be fish's pid).
|
|
|
|
# So run it twice and verify that everything agrees; this implies that it could
|
|
|
|
# not have used any of the pids of the child procs.
|
2020-01-13 19:34:22 +00:00
|
|
|
function nothing
|
|
|
|
end
|
|
|
|
nothing | $fth print_pgrp | read -g a0 | save_pgroup a1 | begin
|
|
|
|
save_pgroup a2
|
|
|
|
end
|
|
|
|
nothing | $fth print_pgrp | read -g b0 | save_pgroup b1 | begin
|
|
|
|
save_pgroup b2
|
|
|
|
end
|
2019-12-08 21:28:30 +00:00
|
|
|
|
|
|
|
[ "$a0" -eq "$a1" ] && [ "$a1" -eq "$a2" ] \
|
2020-01-13 19:34:22 +00:00
|
|
|
&& [ "$b0" -eq "$b1" ] && [ "$b1" -eq "$b2" ] \
|
|
|
|
&& [ "$a0" -eq "$b0" ]
|
2019-12-08 21:28:30 +00:00
|
|
|
and echo "All pgroups agreed"
|
|
|
|
or echo "Pgroups disagreed. Found $a0 $a1 $a2, and $b0 $b1 $b2"
|
|
|
|
# CHECK: All pgroups agreed
|
2020-02-20 19:18:36 +00:00
|
|
|
|
2020-04-26 00:11:36 +00:00
|
|
|
# Ensure that eval retains pgroups - #6806.
|
2020-09-13 20:18:01 +00:00
|
|
|
set -l tmpfile1 (mktemp)
|
|
|
|
set -l tmpfile2 (mktemp)
|
|
|
|
$fth print_pgrp > $tmpfile1 | eval '$fth print_pgrp > $tmpfile2'
|
|
|
|
read -l pgrp1 < $tmpfile1
|
|
|
|
read -l pgrp2 < $tmpfile2
|
|
|
|
[ "$pgrp1" -eq "$pgrp2" ]
|
|
|
|
and echo "eval pgroups agreed"
|
|
|
|
or echo "eval pgroups disagreed, meaning eval does not retain pgroups: $pgrp1 $pgrp2"
|
|
|
|
# CHECK: eval pgroups agreed
|
2020-09-13 20:23:56 +00:00
|
|
|
echo -n > $tmpfile1
|
|
|
|
echo -n > $tmpfile2
|
2020-04-26 00:11:36 +00:00
|
|
|
|
2020-02-20 19:18:36 +00:00
|
|
|
# Ensure that if a background job launches another background job, that they have different pgroups.
|
|
|
|
# Our regex will capture the first pgroup and use a negative lookahead on the second.
|
|
|
|
status job-control full
|
2020-09-13 20:23:56 +00:00
|
|
|
$fth print_pgrp > $tmpfile1 | begin
|
|
|
|
$fth print_pgrp > $tmpfile2 &
|
|
|
|
wait
|
2020-02-20 19:18:36 +00:00
|
|
|
end &
|
|
|
|
wait
|
2020-09-13 20:23:56 +00:00
|
|
|
read -l pgrp1 < $tmpfile1
|
|
|
|
read -l pgrp2 < $tmpfile2
|
|
|
|
[ "$pgrp1" -ne "$pgrp2" ]
|
|
|
|
and echo "background job correctly got new pgroup"
|
|
|
|
or echo "background job did not get new pgroup: $pgrp1 $pgrp2"
|
|
|
|
# CHECK: background job correctly got new pgroup
|
|
|
|
rm $tmpfile1 $tmpfile2
|