Commit 345effcd authored by pcy's avatar pcy
Browse files

use awk in sspt-strace

parent d6dcf680
......@@ -21,61 +21,48 @@ OUTFILE=""
run_strace() {
# not using -e trace=%file because I don't care about eg. the stat syscalls
local SYSCALLS="open,openat,creat,link,linkat,mkdir,mkdirat,rename,renameat,renameat2,rmdir,symlink,symlinkat" # ,unlink,unlinkat
local AWK_SCRIPT='$1 ~ /^open$|^creat$|^mkdir$|^rmdir$|^symlink$/ {print $2} $1 ~ /^openat$|^link$|^mkdirat$|^rename$/ {print $3} $1 ~ /^symlinkat$/ {print $4} $1 ~ /^linkat$|^renameat$|^renameat2$/ {print $5}'
local AWK=''
if command -v "mawk" >/dev/null 2>&1; then
AWK='mawk'
elif command -v "gawk" >/dev/null 2>&1; then
AWK='gawk'
elif command -v "awk" >/dev/null 2>&1; then
AWK='awk'
else
(>&2 echo "A version of awk is required.")
exit 1
fi
local STRACE_OUT="$(temp_filename)"
local GREP_OUT="$(temp_filename)"
# v only interested in paths, not any other kind of string
local DESTDIR_ESC="$(echo "$SSPT_DEST_DIR" | sed -Ee 's/\//\\\//g')"
local DBDIR_ESC="$(echo "$SSPT_DB_DIR" | sed -Ee 's/\//\\\//g')"
local DLDIR_ESC="$(echo "$SSPT_DL_DIR" | sed -Ee 's/\//\\\//g')"
# v only interested in paths, not any other kind of string
strace -f -a 80 -s 0 -qq -o "$STRACE_OUT" -e trace="$SYSCALLS" \
bash -c "'$SSPT_THISSCRIPT' pkgcmd install '$1'"
# 1. select only files that are written to
# 2,3. but also add stuff that doesn't use these flags
# 4. filter out uninteresting places
# 5. filter out local stuff & db operations
# 6. throw away PID & retval (it'd be much cleaner if it wouldn't
# 4. throw away PID & retval (it'd be much cleaner if it wouldn't
# pretty-print errors)
# 5. grab the dest path
# 6. filter out uninteresting places
# 7. filter out duplicates
< "$STRACE_OUT" grep -e O_RDWR -e O_WRONLY \
-e creat -e link -e linkat -e mkdir -e mkdirat -e rename \
-e renameat2 -e renameat2 -e rmdir -e symlink -e symlinkat \
| grep -Ev -e '\(\"\/dev\/' -e '"\(\"\/tmp\/' -e '"\(\"[^\/]' -e '"\(\"\/home\"' \
| grep -Fv -e "$SSPT_DL_DIR" -e "$SSPT_DB_DIR" \
| sed -E -e 's/^[0-9]* *//' -e 's/\) *=.*/\)/' \
| sed -E -e 's/^[0-9]* *//' -e 's/\) *=.*/\)/' -e 's/\(/, /' -e 's/\)$//' \
| "$AWK" -F', ' "$AWK_SCRIPT" \
| grep -E "^\"$DESTDIR_ESC" | grep -Ev -e "^\"$DBDIR_ESC" -e "^\"$DLDIR_ESC" \
| sort | uniq -u \
> "$GREP_OUT" # I told you, this is total madness
rm "$STRACE_OUT"
while read -r LINE; do
local SYSCALL=$(echo "$LINE" | sed -E -e 's/\(.*$//')
local ALLARG_=$(echo "$LINE" | sed -E -e 's/^.*?\(//' -e 's/\)$//')
IFS=', '
read -ra ALLARGS <<< "$ALLARG_"
unset IFS
local OUTFIL=""
case "$SYSCALL" in
"open"|"creat"|"mkdir"|"rmdir"|"symlink")
OUTFIL="${ALLARGS[0]}"
;;
"openat"|"link"|"mkdirat"|"rename")
OUTFIL="${ALLARGS[1]}"
;;
"symlinkat")
OUTFIL="${ALLARGS[2]}"
;;
"linkat"|"renameat"|"renameat2")
OUTFIL="${ALLARGS[3]}"
;;
*)
(>&2 echo "Unexpeted strace output '$LINE'!")
unset OUTFILE
exit 1
;;
esac
echo "$OUTFIL" >> "$STRACE_OUT" # reuse the file
done < "$GREP_OUT"
rm "$GREP_OUT"
OUTFILE="$STRACE_OUT"
OUTFILE="$GREP_OUT"
}
main() {
......@@ -99,12 +86,12 @@ main() {
echo "NOTE: installing package '$1' whose installed files" \
" will not be tracked by sspt. This will make \`sspt" \
" uninstall\` meaningless for this package."
exec_subcommand pkgcmd install "$1" || exit -1
exec_subcommand pkgcmd install "$1" || exit 1
OUTFILE="$(temp_filename)"
touch "$OUTFILE"
fi
exec_subcommand bin-db reg "$1" "$OUTFILE" || exit -1
exec_subcommand bin-db reg "$1" "$OUTFILE" || exit 1
rm "$OUTFILE"
;;
esac
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment