From c326746053f9d25f9feafa5eab55133c0a07ca15 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 16 Mar 2014 12:20:04 +0100 Subject: [PATCH] tracefile: Deal with chdir and relative files. --- tracefile/tracefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tracefile/tracefile b/tracefile/tracefile index 1df9c00..19898f9 100755 --- a/tracefile/tracefile +++ b/tracefile/tracefile @@ -12,12 +12,20 @@ if(not ($opt::exists or $opt::nonexists or $opt::all)) { } my @cmd = shell_quote(@ARGV); +my $dir = "."; open(IN, "-|", "strace -ff -e trace=file @cmd 2>&1") || die; while() { + if(/chdir."(([^\\"]|\\[\\"nt])*)".\s*=\s*0/) { + $dir = $1; + } + + # [pid 30817] stat("transpose/100000files.tar.gz", {st_mode=S_IFREG|0644, st_size=140853248, ...}) = 0 if(s/^[^\"]+"(([^\\"]|\\[\\"nt])*)".*/$1/) { # Matches the strace structure for a file my $file = shell_unquote($1); + # Relative to $dir + $file =~ s:^([^/]):$dir/$1:; my $print = 0; if($opt::all or @@ -29,7 +37,7 @@ while() { if($opt::unique and $seen{$file}++) { $print = 0; } - $print and print; + $print and print $file,"\n"; } }