- (tim) [openbsd-compat/glob.h] Remove sys/cdefs.h include that came with
[openssh-git.git] / fixprogs
blobaf76ee3924569e3e3e73279f0f110d0642689d5a
1 #!/usr/bin/perl
3 # fixprogs - run through the list of entropy commands and
4 # score out the losers
7 $entscale = 50; # divisor for optional entropy measurement
9 sub usage {
10 return("Usage: $0 <command file>\n");
13 if (($#ARGV == -1) || ($#ARGV>1)) {
14 die(&usage);
17 # 'undocumented' option - run ent (in second param) on the output
18 if ($#ARGV==1) {
19 $entcmd=$ARGV[1]
20 } else {
21 $entcmd = ""
24 $infilename = $ARGV[0];
26 if (!open(IN, "<".$infilename)) {
27 die("Couldn't open input file");
29 $outfilename=$infilename.".out";
30 if (!open(OUT, ">$outfilename")) {
31 die("Couldn't open output file $outfilename");
33 @infile=<IN>;
35 select(OUT); $|=1; select(STDOUT);
37 foreach (@infile) {
38 if (/^\s*\#/ || /^\s*$/) {
39 print OUT;
40 next;
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;
47 open (STDIN, "</dev/null");
48 open (STDOUT, ">/dev/null");
49 open (STDERR, ">/dev/null");
50 exec $path @args;
51 exit 1; # shouldn't be here
53 # parent
54 waitpid ($pid, 0); $ret=$? >> 8;
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
69 print OUT "\"$cmd\" $path $est\n";
72 close(IN);