X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=data%2FPVE%2FTools.pm;h=5b30aedbdbb40079e270236d2160c018c632f407;hp=f8e9c4773dbe94ed7e57d1c9de5102d96410b85e;hb=eb7e5538615974e1e72a92c8e5812781374df25d;hpb=2f13cbb5a6557da77c644e112c09d797066496ea diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index f8e9c47..5b30aed 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -882,7 +882,9 @@ sub decode_utf8_parameters { sub random_ether_addr { - my $rand = Digest::SHA::sha1_hex(rand(), time()); + my ($seconds, $microseconds) = gettimeofday; + + my $rand = Digest::SHA::sha1_hex($$, rand(), $seconds, $microseconds); my $mac = ''; for (my $i = 0; $i < 6; $i++) { @@ -930,7 +932,7 @@ sub split_args { } sub dump_logfile { - my ($filename, $start, $limit) = @_; + my ($filename, $start, $limit, $filter) = @_; my $lines = []; my $count = 0; @@ -946,12 +948,25 @@ sub dump_logfile { $limit = 50 if !$limit; my $line; - while (defined($line = <$fh>)) { - next if $count++ < $start; - next if $limit <= 0; - chomp $line; - push @$lines, { n => $count, t => $line}; - $limit--; + + if ($filter) { + # duplicate code, so that we do not slow down normal path + while (defined($line = <$fh>)) { + next if $line !~ m/$filter/; + next if $count++ < $start; + next if $limit <= 0; + chomp $line; + push @$lines, { n => $count, t => $line}; + $limit--; + } + } else { + while (defined($line = <$fh>)) { + next if $count++ < $start; + next if $limit <= 0; + chomp $line; + push @$lines, { n => $count, t => $line}; + $limit--; + } } close($fh); @@ -996,4 +1011,12 @@ sub dir_glob_foreach { } } +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"; + } +} + 1;