File: case-20-epoll.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 (35 lines) | stat: -rwxr-xr-x 827 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
#!/bin/bash
source tests/common.bash

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

$TARGET 2>> $report | {
    read pid epfd evfd0 evfd1
    if [[ -z "$pid" || -z "$epfd" || -z "$evfd0" || -z "$evfd1" ]]; then
	echo "unexpected output form target ( $TARGET )" >> $report
	exit 1
    fi
    if ! [ -e "/proc/$pid" ]; then
	echo "the target process dead unexpectedly" >> $report
	exit 1
    fi
    {
	echo pid: $pid
	echo epfd: $epfd
	echo cmdline: "$lsof -p $pid -a -d $epfd"
	$lsof -p $pid -a -d $epfd
	echo done
    } >> $report
    if $lsof -p $pid -a -d $epfd |
	    grep -q "epoll *[0-9]* *.* *${epfd}u *a_inode *[0-9]*,[0-9]* *[0-9]* *[0-9]* *\[eventpoll:${evfd0},${evfd1}\]"; then
	kill $pid
	exit 0
    else
	kill $pid
	exit 1
    fi
}