blob: af76ee3924569e3e3e73279f0f110d0642689d5a [file] [log] [blame]
Damien Miller912d9752000-05-18 23:12:50 +10001#!/usr/bin/perl
2#
3# fixprogs - run through the list of entropy commands and
4# score out the losers
5#
6
7$entscale = 50; # divisor for optional entropy measurement
8
9sub usage {
10 return("Usage: $0 <command file>\n");
11}
12
13if (($#ARGV == -1) || ($#ARGV>1)) {
14 die(&usage);
15}
16
17# 'undocumented' option - run ent (in second param) on the output
18if ($#ARGV==1) {
19 $entcmd=$ARGV[1]
20} else {
21 $entcmd = ""
22};
23
24$infilename = $ARGV[0];
25
26if (!open(IN, "<".$infilename)) {
27 die("Couldn't open input file");
28}
29$outfilename=$infilename.".out";
30if (!open(OUT, ">$outfilename")) {
31 die("Couldn't open output file $outfilename");
32}
33@infile=<IN>;
34
35select(OUT); $|=1; select(STDOUT);
36
37foreach (@infile) {
38 if (/^\s*\#/ || /^\s*$/) {
39 print OUT;
40 next;
41 }
42 ($cmd, $path, $est) = /^\"([^\"]+)\"\s+([\w\/_-]+)\s+([\d\.\-]+)/o;
43 @args = split(/ /, $cmd);
44 if (! ($pid = fork())) {
45 # child
46 close STDIN; close STDOUT; close STDERR;
Damien Miller606f8802000-09-16 15:39:56 +110047 open (STDIN, "</dev/null");
Damien Milleraeaa1262000-09-16 16:10:56 +110048 open (STDOUT, ">/dev/null");
Damien Miller606f8802000-09-16 15:39:56 +110049 open (STDERR, ">/dev/null");
Damien Miller912d9752000-05-18 23:12:50 +100050 exec $path @args;
51 exit 1; # shouldn't be here
52 }
53 # parent
54 waitpid ($pid, 0); $ret=$? >> 8;
55
56 if ($ret != 0) {
57 $path = "undef";
58 } else {
59 if ($entcmd ne "") {
60 # now try to run ent on the command
61 $mostargs=join(" ", splice(@args,1));
62 print "Evaluating '$path $mostargs'\n";
63 @ent = qx{$path $mostargs | $entcmd -b -t};
64 @ent = grep(/^1,/, @ent);
65 ($null, $null, $rate) = split(/,/, $ent[0]);
66 $est = $rate / $entscale; # scale the estimate back
67 }
Damien Millera8e06ce2003-11-21 23:48:55 +110068 }
Damien Miller912d9752000-05-18 23:12:50 +100069 print OUT "\"$cmd\" $path $est\n";
70}
71
72close(IN);