blob: c4d94509c5f7bf75f84ec768508dfdbbf7eea69a [file] [log] [blame]
Dmitry V. Levinf23b0972014-05-29 21:35:34 +00001#!/bin/sh
2
3# Check how SCM_RIGHTS 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 grep
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000012
13rm -f $LOG.*
14
15./scm_rights ||
16 fail_ 'scm_rights failed'
17
18args="-tt -ff -y -xx -enetwork -o $LOG ./scm_rights"
19$STRACE $args ||
20 fail_ "$STRACE $args failed"
21
22"$srcdir"/../strace-log-merge $LOG > $LOG || {
23 cat $LOG
24 fail_ 'strace-log-merge failed'
25}
26rm -f $LOG.*
27
28grep_log()
29{
30 local syscall="$1"; shift
31 local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
32
33 LC_ALL=C grep -E -x "$prefix$syscall$*" $LOG > /dev/null || {
34 cat $LOG
35 fail_ "$STRACE $args failed to trace \"$syscall\" properly"
36 }
37}
38
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +000039n='[1-9][0-9]*'
40msg='\{msg_name\(0\)=NULL, msg_iov\(1\)=\[\{"\\x00\\x00\\x00\\x00[^"]*", '"$n"'\}\], msg_controllen='"$n"
41rights='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, \[3</dev/null>, 4</dev/zero>\]\}'
42creds='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS, \{pid='"$n"', uid=[0-9]+, gid=[0-9]+\}\}'
43grep_log sendmsg '\(1<socket:\[[0-9]+\]>, '"$msg"', \['"$rights"'\], msg_flags=0\}, 0\) += '"$n"
44grep_log recvmsg '\(0<socket:\[[0-9]+\]>, '"$msg"', \['"$creds"', '"$rights"'\], msg_flags=0\}, 0\) += '"$n"
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000045
46exit 0