summaryrefslogtreecommitdiffstats
path: root/tests/posix/readdir_error.sh
blob: fc48eb129541bc6387e8025424691c034ab4df87 (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
34
35
36
37
test "$UNAME" = "Linux" || skip

clean_scratch
mkfifo scratch/{fever,pid,wait,running}

(
    # Create a zombie process
    cat scratch/fever >/dev/null &
    # Write the PID to scratch/pid
    echo $! >scratch/pid
    # Don't wait on the zombie process
    exec cat scratch/wait scratch/fever >scratch/running
) &

# Kill the parent cat on exit
defer kill -9 %1

# Read the child PID
read -r pid <scratch/pid

# Make sure the parent cat is running before we kill the child, because bash
# will wait() on its children
echo >scratch/wait &
read -r _ <scratch/running

# Turn the child into a zombie
kill -9 "$pid"

# Wait until it's really a zombie
state=R
while [ "$state" != "Z" ]; do
    read -r _ _ state _ <"/proc/$pid/stat"
done

# On Linux, open(/proc/$pid/net) will succeed but readdir() will fail
test -r "/proc/$pid/net" || skip
! invoke_bfs "/proc/$pid/net" >/dev/null