summaryrefslogtreecommitdiff
path: root/src/watch-entropy
blob: e0f3261032ab999824903a08e94059c28267f57e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl
$SIG{INT} = sub { ++$interrupted; };
use Time::HiRes qw(sleep);
use constant default_file => "/proc/sys/kernel/random/entropy_avail";
use constant default_format => 'system entropy: %-5d bits';
$|++;
my $file = shift || default_file;
my $format = $file eq default_file ? default_format : "$file: %s";
my $sleep_time = shift || 0.2;
open ENT, "<", $file or die "$0: error opening $file: $!\n";
my $last; while (<ENT>) {
  chomp;
  printf "
$format", $_ . (" " x (length($last) - length $_)) unless $_ eq $last;
  $last = $_;
  last if $interrupted;
  sleep $sleep_time;
  seek ENT, 0, 0;
}
print "\n";