summaryrefslogtreecommitdiffhomepage
path: root/tests/zos/fdmap.sh
blob: b63a19923bed1cbfc4d85137beed69032ec0f756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# z/OS: spawn() fd_map edge cases - closed descriptors in the shell must
# become SPAWN_FDCLOSED, never an EBADF from spawn().
exec 3>&- 4>&- 5>&-
/bin/sh -c 'echo "fds closed ok"'
/bin/sh -c 'echo x >&3' 2>/dev/null || echo "3 stays closed"
exec <&-
/bin/sh -c 'echo "stdin closed in parent ok"'
/bin/sh -c 'echo to9 >&9' 9>&1
exec 2>&-
/bin/sh -c 'echo "stderr closed in parent ok"'
/bin/sh -c 'echo piped' | /bin/cat
x=$(/bin/sh -c 'echo captured'); echo "$x"
# A script's descriptors are 0..9 (src/sys.h:15); the shell's own live
# above them.  Fill the script's range and spawn: the terminal is
# duplicated above it, and must still reach the child.
mkdir -p many
i=3
while [ $i -le 9 ]; do
    eval "exec $i>many/f$i"
    i=$((i + 1))
done
/bin/sh -c 'echo "script descriptors ok"'
i=3
while [ $i -le 9 ]; do
    eval "exec $i>&-"
    i=$((i + 1))
done
/bin/sh -c 'echo "and closed again"'
# The map hands the child the shell's own pipe descriptors.  They are
# close-on-exec (sys_pipe()), and spawn() keeps the flag, so a grandchild
# that execs would lose the pipe -- ps printed EDC5113I Bad file
# descriptor.  The map must pass a duplicate without the flag.
/bin/sh -c 'exec /bin/echo survives exec' | /bin/cat