rpmsafe: realpath fixes
[nethome.git] / bin / ptracegrep
1 #! /bin/sh
2 # $Id$
3
4 if [ "$1" = "-n" ];then
5         n=true
6         shift
7 else
8         n=false
9 fi
10
11 if [ -n "$2" ];then
12         PID="$2"
13 else
14         PIDS="$(sed -n 's/^ptrace *(PTRACE_ATTACH, *\([0-9]*\),.*$/\1/p' "$1"|sort -u)"
15         if [ -z "$PIDS" ];then
16                 echo >&2 "No PIDS found!"
17                 exit 1
18         fi
19         PID='\('"$(echo "$PIDS"|tr '\n' ','|sed -e 's/,$//' -e 's/,/\\|/g')"'\)'
20 fi
21 echo >&2 "PID=$PID"
22 grep $PID $1 \
23         | grep -v '^\(\(open\|read\|write\) *(\|ptrace *( *PTRACE_\(PEEK\|POKE\)\)' \
24         | if $n;then cat;else sed -e 's/\<'$PID'\>/PID/g' -e 's/0x[0-9a-f]\{5,\}/HEX/g';fi