File: case-20-pipe-endpoint.bash

package info (click to toggle)
lsof 4.99.4%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,924 kB
  • sloc: ansic: 50,680; sh: 8,351; makefile: 1,194; perl: 940; awk: 214
file content (39 lines) | stat: -rwxr-xr-x 1,098 bytes parent folder | download
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
38
39
#!/bin/bash
source tests/common.bash

TARGET=$tcasedir/pipe
if ! [ -x $TARGET ]; then
    echo "target executable ( $TARGET ) is not found" >> $report
    exit 1
fi

{ $TARGET & } | {
    read parent child fdr fdw;
    if [ -z "$parent" ] || [ -z "$child" ] || [ -z "$fdr" ] || [ -z "$fdw" ]; then
	echo "unexpected output form target ( $TARGET )" >> $report
	exit 1
    fi
    echo parent: $parent >> $report
    echo child:  $child >> $report
    echo fdr:    $fdr >> $report
    echo fdw:    $fdw >> $report
    echo cmdline: "$lsof +E -p "$parent"" >> $report
    $lsof +E -p "$parent" >> $report

    {
	{
	    echo expected pattern: ".* $parent .* ${fdr}r *FIFO .* pipe ${child},p[-a-z]*,${fdw}w"
	    $lsof +E -p "$parent" |
		grep -q ".* $parent .* ${fdr}r *FIFO .* pipe ${child},p[-a-z]*,${fdw}w"
	} && {
	    echo expected parent: ".* $child .* ${fdw}w *FIFO .* pipe ${parent},p[-a-z]*,${fdr}r"
	    $lsof +E -p "$parent" |
		grep -q ".* $child .* ${fdw}w *FIFO .* pipe ${parent},p[-a-z]*,${fdr}r"
	} && {
	    kill "$child"
	    exit 0
	}
    } >> $report
    kill "$child"
    exit 1
}