blob: 1974e0d58b8ef04def531c845d6daafeb86d9927 [file] [log] [blame]
Dmitry V. Levinf23b0972014-05-29 21:35:34 +00001#!/bin/sh
2
Dmitry V. Levinc7235992015-01-24 19:51:39 +00003# Check how SCM_RIGHTS and SCM_CREDENTIALS control messages are decoded in -y mode.
Dmitry V. Levinf23b0972014-05-29 21:35:34 +00004
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. Levinc7235992015-01-24 19:51:39 +000012check_prog mkdir
13check_prog rm
14check_prog seq
15check_prog touch
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000016
Dmitry V. Levinc7235992015-01-24 19:51:39 +000017rm -rf -- "$LOG".*
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000018
Dmitry V. Levinc7235992015-01-24 19:51:39 +000019dir="$LOG.dir"
20mkdir -- "$dir" ||
21 framework_skip_ 'failed to create a directory'
22
23file="$dir/$(for i in $(seq 1 127); do echo A; done; echo Z)"
24
25touch -- "$file" ||
26 framework_skip_ 'failed to create a file'
27
28./scm_rights /dev/zero ||
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000029 fail_ 'scm_rights failed'
30
Dmitry V. Levinc7235992015-01-24 19:51:39 +000031args="-tt -ff -y -x -enetwork ./scm_rights /dev/zero"
32$STRACE -o "$LOG" $args "$file" ||
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000033 fail_ "$STRACE $args failed"
34
Dmitry V. Levinc7235992015-01-24 19:51:39 +000035"$srcdir"/../strace-log-merge "$LOG" > "$LOG" || {
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000036 cat $LOG
37 fail_ 'strace-log-merge failed'
38}
Dmitry V. Levinc7235992015-01-24 19:51:39 +000039
40rm -rf -- "$LOG".*
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000041
42grep_log()
43{
44 local syscall="$1"; shift
45 local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
46
47 LC_ALL=C grep -E -x "$prefix$syscall$*" $LOG > /dev/null || {
48 cat $LOG
49 fail_ "$STRACE $args failed to trace \"$syscall\" properly"
50 }
51}
52
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +000053n='[1-9][0-9]*'
54msg='\{msg_name\(0\)=NULL, msg_iov\(1\)=\[\{"\\x00\\x00\\x00\\x00[^"]*", '"$n"'\}\], msg_controllen='"$n"
Dmitry V. Levinc7235992015-01-24 19:51:39 +000055rights='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, \[3</dev/null>, 4</dev/zero>, 5</[^}>]*/(A\\n){127}Z>\]\}'
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +000056creds='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS, \{pid='"$n"', uid=[0-9]+, gid=[0-9]+\}\}'
57grep_log sendmsg '\(1<socket:\[[0-9]+\]>, '"$msg"', \['"$rights"'\], msg_flags=0\}, 0\) += '"$n"
58grep_log recvmsg '\(0<socket:\[[0-9]+\]>, '"$msg"', \['"$creds"', '"$rights"'\], msg_flags=0\}, 0\) += '"$n"
Dmitry V. Levinf23b0972014-05-29 21:35:34 +000059
60exit 0