X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=data%2FPVE%2FTools.pm;h=b666e9b8e915e7e08c4edbdac63593e071ae5a00;hb=940be49b86e183eef1459fcf2fed41df5d5659e3;hp=5b30aedbdbb40079e270236d2160c018c632f407;hpb=eb7e5538615974e1e72a92c8e5812781374df25d;p=pve-common.git diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 5b30aed..b666e9b 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -19,6 +19,9 @@ use Text::ParseWords; use String::ShellQuote; use Time::HiRes qw(usleep gettimeofday tv_interval); +# avoid warning when parsing long hex values with hex() +no warnings 'portable'; # Support for 64-bit ints required + our @EXPORT_OK = qw( $IPV6RE $IPV4RE @@ -142,8 +145,7 @@ sub lock_file_full { $err = $@; } - if ($lock_handles->{$$}->{$filename}) { - my $fh = $lock_handles->{$$}->{$filename}; + if (my $fh = $lock_handles->{$$}->{$filename}) { $lock_handles->{$$}->{$filename} = undef; close ($fh); } @@ -690,7 +692,7 @@ sub next_unused_port { next if $ports->{$p}; # reserved my $sock = IO::Socket::INET->new(Listen => 5, - LocalAddr => 'localhost', + LocalAddr => '0.0.0.0', LocalPort => $p, ReuseAddr => 1, Proto => 0); @@ -1015,8 +1017,30 @@ sub assert_if_modified { my ($digest1, $digest2) = @_; if ($digest1 && $digest2 && ($digest1 ne $digest2)) { - die "detected modified configuration - file change by other user? Try again.\n"; + die "detected modified configuration - file changed by other user? Try again.\n"; } } +# Digest for short strings +# like FNV32a, but we only return 31 bits (positive numbers) +sub fnv31a { + my ($string) = @_; + + my $hval = 0x811c9dc5; + + foreach my $c (unpack('C*', $string)) { + $hval ^= $c; + $hval += ( + (($hval << 1) ) + + (($hval << 4) ) + + (($hval << 7) ) + + (($hval << 8) ) + + (($hval << 24) ) ); + $hval = $hval & 0xffffffff; + } + return $hval & 0x7fffffff; +} + +sub fnv31a_hex { return sprintf("%X", fnv31a(@_)); } + 1;