1#!/bin/gawk 2# 3# Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com> 4# Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org> 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 3. The name of the author may not be used to endorse or promote products 16# derived from this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29BEGIN { 30 lines = 8 31 fail = 0 32 33 addrlen = length(addr) + 3 34 r_i = "[1-9][0-9]*" 35 r_socket = "^socket\\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\\) += 0<UNIX:\\[(" r_i ")\\]>$" 36} 37 38NR == 1 { 39 if (match($0, r_socket, a)) { 40 inode_listen = a[2] 41 r_bind = "^bind\\(0<UNIX:\\[" inode_listen "\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), sun_path=\"" addr "\"\\}, " addrlen "\\) += 0$" 42 r_listen = "^listen\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>, 5\\) += 0$" 43 r_getsockname = "^getsockname\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), sun_path=\"" addr "\"\\}, \\[" addrlen "\\]\\) += 0$" 44 r_accept = "^accept\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), NULL\\}, \\[2\\]\\) += 1<UNIX:\\[(" r_i ")->(" r_i "),\"" addr "\"\\]>" 45 next 46 } 47} 48 49NR == 2 {if (r_bind != "" && match($0, r_bind)) next} 50 51NR == 3 {if (r_listen != "" && match($0, r_listen)) next} 52 53NR == 4 {if (r_getsockname != "" && match($0, r_getsockname)) next} 54 55NR == 5 { 56 if (r_accept != "" && match($0, r_accept, a)) { 57 inode_accepted = a[2] 58 inode_peer = a[3] 59 r_close_listen = "^close\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>\\) += 0$" 60 r_close_accepted = "^close\\(1<UNIX:\\[" inode_accepted ",\"" addr "\"\\]>\\) += 0$" 61 next 62 } 63} 64 65NR == 6 {if (r_close_listen != "" && match($0, r_close_listen)) next} 66NR == 7 {if (r_close_accepted != "" && match($0, r_close_accepted)) next} 67 68NR == lines && $0 == "+++ exited with 0 +++" {next} 69 70{ 71 print "Line " NR " does not match: " $0 72 fail=1 73} 74 75END { 76 if (NR != lines) { 77 print "Expected " lines " lines, found " NR " line(s)." 78 print "" 79 exit 1 80 } 81 if (fail) { 82 print "" 83 exit 1 84 } 85} 86