History

leaking_addresses: add timeout on file read

Currently script can stall if we read certain files (like /proc/kmsg). While we have a mechanism to skip these files once they are discovered it would be nice to not stall on as yet undiscovered files of this kind. Set a timer before each file is parsed, warn user if timer expires.

Tobin C. Harding committed 9 years ago

Commit dd98c251 parent 62139c11 file · +21 −1Browse files

Unified · Split

scripts/leaking_addresses.pl+21−1
@@ -29,6 +29,9 @@ my $V = '0.01'; · 28 unmodified lines
29# Directories to scan.29# Directories to scan.
30my @DIRS = ('/proc', '/sys');30my @DIRS = ('/proc', '/sys');
31 31
32# Timer for parsing each file, in seconds.
33my $TIMEOUT = 10;
34
32# Script can only grep for kernel addresses on the following architectures. If35# Script can only grep for kernel addresses on the following architectures. If
33# your architecture is not listed here and has a grep'able kernel address please36# your architecture is not listed here and has a grep'able kernel address please
34# consider submitting a patch.37# consider submitting a patch.
@@ -284,6 +287,23 @@ sub skip_parse · 249 unmodified lines
284 return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any);287 return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any);
285}288}
286 289
290sub timed_parse_file
291{
292 my ($file) = @_;
293
294 eval {
295 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required.
296 alarm $TIMEOUT;
297 parse_file($file);
298 alarm 0;
299 };
300
301 if ($@) {
302 die unless $@ eq "alarm\n"; # Propagate unexpected errors.
303 printf STDERR "timed out parsing: %s\n", $file;
304 }
305}
306
287sub parse_file307sub parse_file
288{308{
289 my ($file) = @_;309 my ($file) = @_;
@@ -335,7 +355,7 @@ sub walk · 45 unmodified lines
335 if (-d $path) {355 if (-d $path) {
336 push @dirs, $path;356 push @dirs, $path;
337 } else {357 } else {
338 parse_file($path);358 timed_parse_file($path);
339 }359 }
340 }360 }
341 }361 }