File: util-open-flags.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 (44 lines) | stat: -rw-r--r-- 1,040 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
40
41
42
43
44
source tests/common.bash

pat=$5
tfile=$6

shift 6

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

export LC_ALL=C

log=/tmp/$name-$$.log
$TARGET $tfile "$@" 2>> $log | {
    read pid

    if  [[ -z "$pid" ]]; then
        cat $log >> $report
        # musl prints "Not supported" instead of "Operation not supported"
        if grep -E -q 'open: (Operation not supported|Not supported)' $log; then
            echo "a flag passed to open is not supported on this platform, skipping" >> $report
            exit 77
        fi
        echo "unexpected output from target ( $TARGET )" >> $report
	exit 1
    fi
    if ! [ -e "/proc/$pid" ]; then
        echo "the target process dead unexpectedly" >> $report
        exit 1
    fi

    echo "expected: $pat" >> $report
    echo "lsof output:" >> $report
    output=$($lsof +fg -p $pid)
    echo "$output" >> $report
    echo "$output" | grep -q "$pat"
    result=$?

    kill $pid
    exit $result
}