Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / findlocks
CommitLineData
805e021f
CE
1#!/usr/bin/perl
2
3use File::Find;
4use IO::File;
5
6use strict;
7use vars qw($Pat @Locks $DupOnly);
8
9# This pattern matches the function names we are looking for
10$Pat = qr/(?:NB)?Obtain(?:Write|Shared|)Lock|UpgradeSToWLock/;
11
12if (@ARGV[0] eq '-d') {
13 $DupOnly = 1;
14 shift @ARGV;
15}
16
17find(
18 sub {
19 return unless -f $_;
20
21 my $path = $File::Find::name;
22 my $F = new IO::File($_, O_RDONLY) or die "$path: $!\n";
23 while (<$F>) {
24 next unless /\b(?:$Pat)\(.*,\s*(\d+)\)/o;
25 $Locks[$1] ||= [];
26 push(@{$Locks[$1]}, sprintf("%s:%d", $path, $.));
27 }
28 $F->close;
29 }, @ARGV);
30
31foreach my $id (0 .. @Locks) {
32 next unless defined $Locks[$id];
33 next if $DupOnly && @{$Locks[$id]} < 2;
34 printf("%5d %s", $id, join(" ", map("$_\n", @{$Locks[$id]})))
35}