Damien Miller | 912d975 | 2000-05-18 23:12:50 +1000 | [diff] [blame] | 1 | #!/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 | |
| 9 | sub usage { |
| 10 | return("Usage: $0 <command file>\n"); |
| 11 | } |
| 12 | |
| 13 | if (($#ARGV == -1) || ($#ARGV>1)) { |
| 14 | die(&usage); |
| 15 | } |
| 16 | |
| 17 | # 'undocumented' option - run ent (in second param) on the output |
| 18 | if ($#ARGV==1) { |
| 19 | $entcmd=$ARGV[1] |
| 20 | } else { |
| 21 | $entcmd = "" |
| 22 | }; |
| 23 | |
| 24 | $infilename = $ARGV[0]; |
| 25 | |
| 26 | if (!open(IN, "<".$infilename)) { |
| 27 | die("Couldn't open input file"); |
| 28 | } |
| 29 | $outfilename=$infilename.".out"; |
| 30 | if (!open(OUT, ">$outfilename")) { |
| 31 | die("Couldn't open output file $outfilename"); |
| 32 | } |
| 33 | @infile=<IN>; |
| 34 | |
| 35 | select(OUT); $|=1; select(STDOUT); |
| 36 | |
| 37 | foreach (@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 Miller | 606f880 | 2000-09-16 15:39:56 +1100 | [diff] [blame] | 47 | open (STDIN, "</dev/null"); |
Damien Miller | aeaa126 | 2000-09-16 16:10:56 +1100 | [diff] [blame] | 48 | open (STDOUT, ">/dev/null"); |
Damien Miller | 606f880 | 2000-09-16 15:39:56 +1100 | [diff] [blame] | 49 | open (STDERR, ">/dev/null"); |
Damien Miller | 912d975 | 2000-05-18 23:12:50 +1000 | [diff] [blame] | 50 | 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 Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 68 | } |
Damien Miller | 912d975 | 2000-05-18 23:12:50 +1000 | [diff] [blame] | 69 | print OUT "\"$cmd\" $path $est\n"; |
| 70 | } |
| 71 | |
| 72 | close(IN); |