fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
954c68c0b
master
1# RUN: fish=%fish %fish -C "set helper %fish_test_helper" %s 2#REQUIRES: command -v %fish_test_helper 3 4# Check that we don't leave stray FDs. 5 6set -l fds( $helper print_fds) 7test " $fds " = "0 1 2" 8or begin 9echo This test needs to have all fds other than0 1 and2 closed before running>&2 10echo Please close the other fds and try again>&2 11exit 1 12end 13 14$helper print_fds 15# CHECK: 0 1 2 16 17$helper print_fds0>&- 18# CHECK: 1 2 19 20$helper print_fds0>&- 2>&- 21# CHECK: 1 22 23false | $helper print_fds0>&- 24# CHECK: 0 1 2 25 26$helper print_fds< /dev/null 27# CHECK: 0 1 2 28 29$helper print_fds< /dev/null 30# CHECK: 0 1 2 31 32$helper print_fds3< /dev/null 33# CHECK: 0 1 2 3 34 35$helper print_fds5>&2 36# CHECK: 0 1 2 5 37 38# This attempts to trip a case where the file opened in fish 39# has the same fd as the redirection. In this case, the dup2 40# does not clear the CLOEXEC bit. 41 42$helper print_fds4< /dev/null 43# CHECK: 0 1 2 4 44 45$helper print_fds5< /dev/null 46# CHECK: 0 1 2 5 47 48$helper print_fds6< /dev/null 49# CHECK: 0 1 2 6 50 51$helper print_fds7< /dev/null 52# CHECK: 0 1 2 7 53 54$helper print_fds8< /dev/null 55# CHECK: 0 1 2 8 56 57$helper print_fds9< /dev/null 58# CHECK: 0 1 2 9 59 60$helper print_fds10< /dev/null 61# CHECK: 0 1 2 10 62 63$helper print_fds11< /dev/null 64# CHECK: 0 1 2 11 65 66$helper print_fds12< /dev/null 67# CHECK: 0 1 2 12 68 69$helper print_fds13< /dev/null 70# CHECK: 0 1 2 13 71 72$helper print_fds14< /dev/null 73# CHECK: 0 1 2 14 74 75$helper print_fds15< /dev/null 76# CHECK: 0 1 2 15 77 78$helper print_fds16< /dev/null 79# CHECK: 0 1 2 16 80 81$helper print_fds17< /dev/null 82# CHECK: 0 1 2 17 83 84$helper print_fds18< /dev/null 85# CHECK: 0 1 2 18 86 87$helper print_fds19< /dev/null 88# CHECK: 0 1 2 19 89 90$helper print_fds20< /dev/null 91# CHECK: 0 1 2 20 92 93# Check heightenization of the redirection file descriptors 94# 95# If heightenization does NOT work, ">$tmpfile" creates a temporary fd on a fd n 96# (n being the first free descriptor) during parsing, then "n>&1" redirects fd n 97# to fd 1 (still stdout at this stage), lastly, ">$tmpfile" redirects fd 1 is 98# redirected to the "temporary" fd n (which is now stdout instead of $tmpfile). 99# 100# If heightenization does work, ">$tmpfile" creates a temporary fd on 10+, 101# then fd n is redirected to fd 1 (still stdout), the fd 1 is redirect to 102# the "temporary" fd 10+ (still $tmpfile) 103# 104# Since we don't know what `n` will be, we need to redirect all the descriptors 105# reserved for the user 106set -l tmpfile( mktemp ) 107printf 'stdout: %s\n' "$ ( $fish -c " $helper print_fds 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 9>&1 > $tmpfile " ) " 108printf "tmp file: %s\n" $( cat $tmpfile ) 109# CHECK: stdout: 110# CHECK: tmp file: 0 1 2 3 4 5 6 7 8 9 111 112# Check heightenization of the file descriptors when sourcing 113echo ' 114path filter /proc/$fish_pid/fd/{3,4,5,6,7,8,9} 115' > " $tmpfile " 116echo start source 117$fish -c"source ' $tmpfile '" 118echo end source 119# CHECK: start source 120# CHECK: end source 121 122# Check heightenization of descriptors for script files passed to fish 123echo start fish 124$fish " $tmpfile " 125echo end fish 126# CHECK: start fish 127# CHECK: end fish