INN commit: trunk (3 files)
INN Commit
rra at isc.org
Fri Jul 3 20:57:26 UTC 2009
Date: Friday, July 3, 2009 @ 13:57:25
Author: iulius
Revision: 8542
* Use Math::BigInt rather than bigint.pl.
* Use Math::BigFloat not to wrongly truncate numbers.
Modified:
trunk/doc/pod/news.pod
trunk/frontends/cnfsheadconf.in
trunk/frontends/cnfsstat.in
---------------------------+
doc/pod/news.pod | 5 ++
frontends/cnfsheadconf.in | 79 ++++++++++++++++++++------------------------
frontends/cnfsstat.in | 76 +++++++++++++++++++++---------------------
3 files changed, 80 insertions(+), 80 deletions(-)
Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod 2009-06-28 11:08:20 UTC (rev 8541)
+++ doc/pod/news.pod 2009-07-03 20:57:25 UTC (rev 8542)
@@ -54,6 +54,11 @@
gzip(1) is now the default UUCP batcher in B<send-uucp>, instead of
compress(1) whose algorithm has patent issues.
+=item *
+
+B<cnfsheadconf> now uses the Perl core module C<Math::BigInt> rather
+than the deprecated F<bigint.pl> library.
+
=back
=head1 Upgrading from 2.4 to 2.5
Modified: frontends/cnfsheadconf.in
===================================================================
--- frontends/cnfsheadconf.in 2009-06-28 11:08:20 UTC (rev 8541)
+++ frontends/cnfsheadconf.in 2009-07-03 20:57:25 UTC (rev 8542)
@@ -2,7 +2,7 @@
# fixscript will replace this line with code to load INN::Config
# $Id$
-#
+#
# Copyright Andreas Lamrecht 1998
# <Andreas.Lamprect at siemens.at>
#
@@ -11,7 +11,7 @@
#
# Modified by Robert R. Collier 1998
# <rob at lspace.org>
-#
+#
# bigint support added by Duane Currie (sandman at hub.org) 1998
#
# cnfsheadconf is originally from cnfsstat 1999
@@ -20,60 +20,51 @@
use vars qw($opt_h $opt_w);
use Getopt::Long;
-# required for >32bit ints
-require 'bigint.pl';
+# Required for >32bit integers.
+use Math::BigInt;
+use Math::BigFloat;
my($conffile) = "$INN::Config::pathetc/cycbuff.conf";
my($storageconf) = "$INN::Config::pathetc/storage.conf";
-# Hex to bigint conversion routine
-# bhex(HEXSTRING) returns BIGINT (with leading + chopped off)
+# Hex to bigint conversion routine.
+# bhex(HEXSTRING) returns BIGINT (with leading + chopped off).
#
-# In most langauge, unlimited size integers are done using string math
-# libraries usually called bigint. (Java, Perl, etc...)
-
+# In most languages, unlimited size integers are done using string math
+# libraries usually called bigint. (Java, Perl, etc.)
+#
# Bigint's are really just strings.
-# Mathematics routines for bigint's:
-
-# bneg(BINT) return BINT negation
-# babs(BINT) return BINT absolute value
-# bcmp(BINT,BINT) return CODE compare numbers (undef,<0,=0,>0)
-# badd(BINT,BINT) return BINT addition
-# bsub(BINT,BINT) return BINT subtraction
-# bmul(BINT,BINT) return BINT multiplication
-# bdiv(BINT,BINT) return (BINT,BINT) division (quo,rem) just quo if scalar
-# bmod(BINT,BINT) return BINT modulus
-# bgcd(BINT,BINT) return BINT greatest common divisor
-# bnorm(BINT) return BINT normalization
-
sub bhex {
my $hexValue = shift;
$hexValue =~ s/^0x//;
- my $integerValue = '0';
+ my $integerValue = Math::BigInt->new('0');
for (my $i = 0; $i < length($hexValue); $i+=2) {
# Could be more efficient going at larger increments, but byte
- # by byte is safer for the case of 9 byte values, 11 bytes, etc..
+ # by byte is safer for the case of 9 byte values, 11 bytes, etc.
- my $byte = substr($hexValue,$i,2);
+ my $byte = substr($hexValue, $i, 2);
my $byteIntValue = hex($byte);
- $integerValue = bmul($integerValue,'256');
- $integerValue = badd($integerValue,"$byteIntValue");
- }
-
- $integerValue =~ s/^\+//;
- return $integerValue;
+ # bmuladd() is only in Perl >= 5.10.0.
+ $integerValue->bmul('256');
+ $integerValue->badd("$byteIntValue");
}
+ my $result = $integerValue->bstr();
+ $result =~ s/^\+//;
+ return $result;
+}
+
sub bint2hex {
- my $d = shift;
- my $o = 0;
+ my $d = shift;
+ my $o = "0";
- while ($d > 0) {
- my $h = bmod("$d",'16');
- $d = bdiv("$d",'16');
+ my $integerValue = Math::BigInt->new("$d");
+ while ($integerValue->is_pos() and not $integerValue->is_zero()) {
+ my $h = $integerValue->copy()->bmod('16')->bstr();
+ $integerValue->bdiv('16');
$h =~ s/^\+//;
$h='a' if $h eq '10';
$h='b' if $h eq '11';
@@ -81,10 +72,10 @@
$h='d' if $h eq '13';
$h='e' if $h eq '14';
$h='f' if $h eq '15';
- $h =~ s/^\+//;
- $o="$h$o";
+ $o="$h$o";
}
+ # The result ends with a "0".
return "$o";
}
@@ -259,7 +250,7 @@
print STDERR "Cannot read $headerlength bytes from file $buffpath...\n";
exit(1);
}
-
+
($magic, $name, $path, $lena, $freea, $updatea, $cyclenuma, $metaname, $orderinmeta, $currentbuff) = unpack("a8 a16 a64 a16 a16 a16 a16 a16 a16 a8", $buff);
if(!$magic) {
@@ -276,14 +267,16 @@
$name =~ s/\0//g;
print " Buffer $name, len: ";
- printf("%.2f", $len / (1024 * 1024));
+ printf("%.2f", Math::BigFloat->new($len) / (1024 * 1024));
print " Mbytes, used: ";
- printf("%.2f Mbytes", $free / (1024 * 1024));
- printf(" (%4.1f%%) %3d cycles\n", 100 * $free/$len, $cyclenum);
+ printf("%.2f Mbytes", Math::BigFloat->new($free) / (1024 * 1024));
+ printf(" (%4.1f%%) %3d cycles\n",
+ 100 * Math::BigFloat->new($free) / Math::BigFloat->new($len),
+ $cyclenum);
print(" Meta $metaname, order: ");
printf("%d", $orderinmeta);
print(", current: $currentbuff");
-
+
print "\n Newest: $nupdate_str, $nago_str ago\n";
if ($opt_w) {
Modified: frontends/cnfsstat.in
===================================================================
--- frontends/cnfsstat.in 2009-06-28 11:08:20 UTC (rev 8541)
+++ frontends/cnfsstat.in 2009-07-03 20:57:25 UTC (rev 8542)
@@ -2,7 +2,7 @@
# fixscript will replace this line with code to load INN::Config
# $Id$
-#
+#
# Copyright Andreas Lamrecht 1998
# <Andreas.Lamprect at siemens.at>
#
@@ -11,7 +11,7 @@
#
# Modified by Robert R. Collier 1998
# <rob at lspace.org>
-#
+#
# bigint support added by Duane Currie (sandman at hub.org) 1998
use vars qw($opt_a $opt_h $opt_l $opt_p $opt_P $opt_s $opt_v);
@@ -108,9 +108,9 @@
($gr, $cl, $min, $max) = split(/:/, $stor{$oclass});
if ($use_syslog) {
if ($min || $max) {
- $logline = sprintf("Class %s for groups matching \"%s\" article size min/max: %d/%d", $oclass, $gr, $min, $max);
+ $logline = sprintf("Class %s for groups matching \"%s\" article size min/max: %d/%d", $oclass, $gr, $min, $max);
} else {
- $logline = sprintf("Class %s for groups matching \"%s\"", $oclass, $gr);
+ $logline = sprintf("Class %s for groups matching \"%s\"", $oclass, $gr);
}
} else {
print STDOUT "Class $oclass";
@@ -140,14 +140,14 @@
print STDERR "Class $ARGV[1] not found ...\n";
}
} else { # Print all Classes
-
+
foreach $c (@storsort) {
($gr, $cl, $min, $max) = split(/:/, $stor{$c});
if ($use_syslog) {
if ($min || $max) {
- $logline = sprintf("Class %s for groups matching \"%s\" article size min/max: %d/%d", $c, $gr, $min, $max);
+ $logline = sprintf("Class %s for groups matching \"%s\" article size min/max: %d/%d", $c, $gr, $min, $max);
} else {
- $logline = sprintf("Class %s for groups matching \"%s\"", $c, $gr);
+ $logline = sprintf("Class %s for groups matching \"%s\"", $c, $gr);
}
} else {
print STDOUT "Class $c ";
@@ -256,7 +256,7 @@
$key{'SIZE'} .= ",0" unless $key{'SIZE'} =~ /,/;
$key{'SIZE'} =~ s/,/:/;
-
+
if (!defined $stor{$key{'OPTIONS'}}) {
$stor{$key{'OPTIONS'}} = "$key{'NEWSGROUPS'}:$key{'CLASS'}:" .
"$key{'SIZE'}:$key{'OPTIONS'}";
@@ -271,21 +271,21 @@
my ($buffpath) = $_[0];
my ($name, $len, $free, $update, $cyclenum, $oldart) =
&get_cycbuff_info($buffpath);
-
+
if ($use_syslog) {
($name) = split(/\s/, $name);
$name =~ s/\0//g;
syslog ('notice', '%s Buffer %s, len: %.2f Mbytes, used: %.2f Mbytes (%4.1f%%) %3d cycles',
- $logline, $name, $len / (1024 * 1024),
- Math::BigFloat->new ($free) / (1024 * 1024),
- 100 * Math::BigFloat->new ($free) / $len, $cyclenum);
+ $logline, $name, Math::BigFloat->new($len) / (1024 * 1024),
+ Math::BigFloat->new($free) / (1024 * 1024),
+ 100 * Math::BigFloat->new($free) / Math::BigFloat->new($len), $cyclenum);
return 0;
}
$name =~ s/\0//g;
print " Buffer $name, size: ", &human_readable($len, 4);
print ", position: ", &human_readable($free, 4);
- printf(" %.2f cycles\n", $cyclenum + Math::BigFloat->new ($free) / $len);
+ printf(" %.2f cycles\n", $cyclenum + Math::BigFloat->new($free) / Math::BigFloat->new($len));
my ($when, $ago) = &make_time($update);
print " Newest: $when, $ago ago\n";
@@ -323,7 +323,7 @@
my $factor = 1024;
my $unit = -1;
- my $oldscaled = Math::BigFloat->new ($val) / $base;
+ my $oldscaled = Math::BigFloat->new($val) / $base;
my $scaled = $oldscaled;
while ( ( int($scaled) > 0 ) && ( $unit < $#name ) ) {
$oldscaled = $scaled;
@@ -366,7 +366,7 @@
#my ($name, $num, $buff, $size) = @_;
$tag = 'cnfs-' . $buffer;
- print 'Target[', $tag, ']: `', "$INN::Config::pathbin/cnfsstat -m ", $buffer, '`', "\n";
+ print 'Target[', $tag, ']: `', "$INN::Config::pathbin/cnfsstat -m ", $buffer, '`', "\n";
print 'MaxBytes[', $tag, ']: ', (&get_cycbuff_info($buff{$buffer}))[1], "\n";
print 'Title[', $tag, ']: ', "${buffer} Usage\n";
print 'Options[', $tag, ']: growright gauge', "\n";
@@ -411,40 +411,40 @@
sub get_cycbuff_info {
my($buffpath) = $_[0];
-
+
my($CNFSMASIZ)=8;
my($CNFSNASIZ)=16;
my($CNFSPASIZ)=64;
my($CNFSLASIZ)=16;
my($headerlength) = $CNFSMASIZ + $CNFSNASIZ + $CNFSPASIZ + (4 * $CNFSLASIZ);
-
+
my($buff, @entries, $e);
my($magic, $name, $path, $lena, $freea, $updatea, $cyclenuma);
-
+
if(! open(BUFF, "< $buffpath") ) {
print STDERR "Cannot open Cycbuff $buffpath ...\n";
exit(1);
}
-
+
$buff = "";
if(! read(BUFF, $buff, $headerlength) ) {
print STDERR "Cannot read $headerlength bytes from file $buffpath...\n";
exit(1);
}
-
+
($magic, $name, $path, $lena, $freea, $updatea, $cyclenuma) =
unpack("a8 a16 a64 a16 a16 a16 a16", $buff);
-
+
if(!$magic) {
print STDERR "Error while unpacking header ...\n";
exit(1);
}
-
+
my($len) = bhex($lena);
my($free) = bhex($freea);
my($update) = hex($updatea);
my($cyclenum) = hex($cyclenuma) - 1;
-
+
if ($opt_a) {
my $pagesize = 16384;
@@ -465,7 +465,7 @@
check_read_return (sysread (BUFF, $buff, $pagesize));
do {
check_read_return (sysread (BUFF, $chunk, $pagesize));
-
+
$buff .= $chunk;
while ($buff =~ /^message-id:\s+(<.*?>)/mi) {
$buff = $POSTMATCH;
@@ -486,7 +486,7 @@
} while ($sentinel -= $pagesize > 0);
}
-done:
+done:
close(BUFF);
return($name,$len,$free,$update,$cyclenum,$oldart);
}
@@ -523,30 +523,32 @@
return $output;
}
-# Hex to bigint conversion routine
-# bhex(HEXSTRING) returns BIGINT (with leading + chopped off)
+# Hex to bigint conversion routine.
+# bhex(HEXSTRING) returns BIGINT (with leading + chopped off).
#
# In most languages, unlimited size integers are done using string math
-# libraries usually called bigint. (Java, Perl, etc...)
-
+# libraries usually called bigint. (Java, Perl, etc.)
+#
# Bigint's are really just strings.
sub bhex {
my $hexValue = shift;
$hexValue =~ s/^0x//;
-
- my $integerValue = new Math::BigInt '0';
+
+ my $integerValue = Math::BigInt->new('0');
for (my $i = 0; $i < length($hexValue); $i += 2) {
# Could be more efficient going at larger increments, but byte
- # by byte is safer for the case of 9 byte values, 11 bytes, etc..
-
+ # by byte is safer for the case of 9 byte values, 11 bytes, etc.
+
my $byte = substr($hexValue, $i, 2);
my $byteIntValue = hex($byte);
- $integerValue = $integerValue * "256";
- $integerValue = $integerValue + "$byteIntValue";
+ # bmuladd() is only in Perl >= 5.10.0.
+ $integerValue->bmul('256');
+ $integerValue->badd("$byteIntValue");
}
- $integerValue =~ s/^\+//;
- return $integerValue;
+ my $result = $integerValue->bstr();
+ $result =~ s/^\+//;
+ return $result;
}
More information about the inn-committers
mailing list