1#!/bin/sh
2
3# Check how SCM_RIGHTS and SCM_CREDENTIALS control messages are decoded in -y mode.
4
5. "${srcdir=.}/init.sh"
6
7# strace -y is implemented using /proc/$pid/fd
8[ -d /proc/self/fd/ ] ||
9	framework_skip_ '/proc/self/fd/ is not available'
10
11check_prog mkdir
12check_prog rm
13check_prog seq
14check_prog touch
15
16dir="$LOG.dir"
17rm -rf -- "$dir"
18mkdir -- "$dir" ||
19	framework_skip_ 'failed to create a directory'
20
21file="$dir/$(for i in $(seq 1 127); do echo A; done; echo Z)"
22
23touch -- "$file" ||
24	framework_skip_ 'failed to create a file'
25
26run_prog ./scm_rights /dev/zero
27run_strace_merge -y -x -enetwork $args "$file"
28
29n='[1-9][0-9]*'
30msg='\{msg_name\(0\)=NULL, msg_iov\(1\)=\[\{"\\x00\\x00\\x00\\x00[^"]*", '"$n"'\}\], msg_controllen='"$n"
31rights='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, \[3</dev/null>, 4</dev/zero>, 5</[^}>]*/(A\\n){127}Z>\]\}'
32creds='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS, \{pid='"$n"', uid=[0-9]+, gid=[0-9]+\}\}'
33prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
34EXPECTED="$LOG.expected"
35
36cat > "$EXPECTED" << __EOF__
37${prefix}sendmsg\\(1<socket:\\[[0-9]+\\]>, $msg, \\[$rights\\], msg_flags=0\\}, 0\\) += $n
38${prefix}recvmsg\\(0<socket:\\[[0-9]+\\]>, $msg, \\[$creds, $rights\\], msg_flags=0\\}, 0\\) += $n
39__EOF__
40
41match_grep "$LOG" "$EXPECTED"
42rm -f "$EXPECTED"
43rm -rf -- "$dir"
44
45exit 0
46