tracefile: Added --local.

This commit is contained in:
Ole Tange 2019-01-08 02:43:10 +01:00
parent 2598055fcb
commit 29c5881869

View file

@ -6,9 +6,9 @@ tracefile - list files being accessed
=head1 SYNOPSIS
B<tracefile> [-adefnruw] I<command>
B<tracefile> [-adeflnruw] I<command>
B<tracefile> [-adefnruw] -p I<pid>
B<tracefile> [-adeflnruw] -p I<pid>
=head1 DESCRIPTION
@ -51,6 +51,14 @@ List only existing files.
List only normal files.
=item B<-l>
=item B<--local>
List only files in current directory. Useful to avoid matching at
system files.
=item B<-n>
=item B<--nonexist>
@ -243,9 +251,6 @@ $Global::progname = "tracefile";
Getopt::Long::Configure("bundling","require_order");
get_options_from_array(\@ARGV) || die_usage();
init_functions();
if(not ($opt::exists or $opt::nonexists or $opt::all or $opt::dir or $opt::file)) {
$opt::all = 1;
}
my @cmd = shell_quote(@ARGV);
my $dir = ".";
@ -258,7 +263,7 @@ while(<IN>) {
}
# [pid 30817] stat("t/tar.gz", {st_mode=S_IFREG|0644, st_size=140853248, ...}) = 0
# openat(AT_FDCWD, "/tmp/a", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
if(/^(\[[^]]\])? # Match pid
if(/^(\[[^]]+\])? # Match pid
\s*([^\" ]+) # function
[(] # (
[^"]* # E.g. AT_FDCWD
@ -272,6 +277,10 @@ while(<IN>) {
my $addinfo = $5;
# Relative to $dir
$file =~ s:^([^/]):$dir/$1:;
$file =~ s:/./:/:g; # /./ => /
$file =~ s:/[^/]+/../:/:g; # /foo/../ => /
# Match files in $PWD or starting with ./
my $local = ($file =~ m<^(\Q$ENV{'PWD'}\E|\./)>);
my $read = readfunc($function,$addinfo);
my $write = writefunc($function,$addinfo);
my $print = 1;
@ -285,6 +294,8 @@ while(<IN>) {
or
($opt::exists and not -e $file)
or
($opt::local and not $local)
or
($opt::nonexists and -e $file)
or
($opt::unique and $seen{$file}++)) {
@ -292,7 +303,6 @@ while(<IN>) {
}
$print and print $file,"\n";
}
}
{
@ -366,6 +376,7 @@ sub options_hash {
"uniq|unique|u" => \$opt::unique,
"exists|exist|e" => \$opt::exists,
"nonexists|nonexist|non-exists|non-exist|n" => \$opt::nonexists,
"local|l" => \$opt::local,
"read|r" => \$opt::read,
"write|w" => \$opt::write,
"all|a" => \$opt::all,