Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 3 | # Check how SCM_RIGHTS and SCM_CREDENTIALS control messages are decoded in -y mode. |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 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 | |
| 11 | check_prog grep |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 12 | check_prog mkdir |
| 13 | check_prog rm |
| 14 | check_prog seq |
| 15 | check_prog touch |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 16 | |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 17 | rm -rf -- "$LOG".* |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 18 | |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 19 | dir="$LOG.dir" |
| 20 | mkdir -- "$dir" || |
| 21 | framework_skip_ 'failed to create a directory' |
| 22 | |
| 23 | file="$dir/$(for i in $(seq 1 127); do echo A; done; echo Z)" |
| 24 | |
| 25 | touch -- "$file" || |
| 26 | framework_skip_ 'failed to create a file' |
| 27 | |
| 28 | ./scm_rights /dev/zero || |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 29 | fail_ 'scm_rights failed' |
| 30 | |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 31 | args="-tt -ff -y -x -enetwork ./scm_rights /dev/zero" |
| 32 | $STRACE -o "$LOG" $args "$file" || |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 33 | fail_ "$STRACE $args failed" |
| 34 | |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 35 | "$srcdir"/../strace-log-merge "$LOG" > "$LOG" || { |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 36 | cat $LOG |
| 37 | fail_ 'strace-log-merge failed' |
| 38 | } |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 39 | |
| 40 | rm -rf -- "$LOG".* |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 41 | |
| 42 | grep_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. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 53 | n='[1-9][0-9]*' |
| 54 | msg='\{msg_name\(0\)=NULL, msg_iov\(1\)=\[\{"\\x00\\x00\\x00\\x00[^"]*", '"$n"'\}\], msg_controllen='"$n" |
Dmitry V. Levin | c723599 | 2015-01-24 19:51:39 +0000 | [diff] [blame] | 55 | rights='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, \[3</dev/null>, 4</dev/zero>, 5</[^}>]*/(A\\n){127}Z>\]\}' |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 56 | creds='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS, \{pid='"$n"', uid=[0-9]+, gid=[0-9]+\}\}' |
| 57 | grep_log sendmsg '\(1<socket:\[[0-9]+\]>, '"$msg"', \['"$rights"'\], msg_flags=0\}, 0\) += '"$n" |
| 58 | grep_log recvmsg '\(0<socket:\[[0-9]+\]>, '"$msg"', \['"$creds"', '"$rights"'\], msg_flags=0\}, 0\) += '"$n" |
Dmitry V. Levin | f23b097 | 2014-05-29 21:35:34 +0000 | [diff] [blame] | 59 | |
| 60 | exit 0 |