9 use File
::Path
qw(make_path);
13 use Fcntl
qw(:DEFAULT :flock);
19 use String
::ShellQuote
;
20 use Time
::HiRes
qw(usleep gettimeofday tv_interval);
22 # avoid warning when parsing long hex values with hex()
23 no warnings
'portable'; # Support for 64-bit ints required
43 my $pvelogdir = "/var/log/pve";
44 my $pvetaskdir = "$pvelogdir/tasks";
49 my $IPV4OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
50 our $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
51 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
52 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
55 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
56 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
57 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
58 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
59 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
60 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
61 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
62 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
63 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
65 sub run_with_timeout
{
66 my ($timeout, $code, @param) = @_;
68 die "got timeout\n" if $timeout <= 0;
76 local $SIG{ALRM
} = sub { $sigcount++; }; # catch alarm outside eval
79 local $SIG{ALRM
} = sub { $sigcount++; die "got timeout\n"; };
80 local $SIG{PIPE
} = sub { $sigcount++; die "broken pipe\n" };
81 local $SIG{__DIE__
}; # see SA bug 4631
83 $prev_alarm = alarm($timeout);
85 $res = &$code(@param);
87 alarm(0); # avoid race conditions
92 alarm($prev_alarm) if defined($prev_alarm);
94 die "unknown error" if $sigcount && !$err; # seems to happen sometimes
101 # flock: we use one file handle per process, so lock file
102 # can be called multiple times and succeeds for the same process.
104 my $lock_handles = {};
107 my ($filename, $timeout, $shared, $code, @param) = @_;
109 $timeout = 10 if !$timeout;
111 my $mode = $shared ? LOCK_SH
: LOCK_EX
;
113 my $lock_func = sub {
114 if (!$lock_handles->{$$}->{$filename}) {
115 $lock_handles->{$$}->{$filename} = new IO
::File
(">>$filename") ||
116 die "can't open file - $!\n";
119 if (!flock ($lock_handles->{$$}->{$filename}, $mode|LOCK_NB
)) {
120 print STDERR
"trying to aquire lock...";
123 $success = flock($lock_handles->{$$}->{$filename}, $mode);
124 # try again on EINTR (see bug #273)
125 if ($success || ($! != EINTR
)) {
130 print STDERR
" failed\n";
131 die "can't aquire lock - $!\n";
133 print STDERR
" OK\n";
139 eval { run_with_timeout
($timeout, $lock_func); };
142 $err = "can't lock file '$filename' - $err";
144 eval { $res = &$code(@param) };
148 if (my $fh = $lock_handles->{$$}->{$filename}) {
149 $lock_handles->{$$}->{$filename} = undef;
165 my ($filename, $timeout, $code, @param) = @_;
167 return lock_file_full
($filename, $timeout, 0, $code, @param);
170 sub file_set_contents
{
171 my ($filename, $data, $perm) = @_;
173 $perm = 0644 if !defined($perm);
175 my $tmpname = "$filename.tmp.$$";
178 my $fh = IO
::File-
>new($tmpname, O_WRONLY
|O_CREAT
, $perm);
179 die "unable to open file '$tmpname' - $!\n" if !$fh;
180 die "unable to write '$tmpname' - $!\n" unless print $fh $data;
181 die "closing file '$tmpname' failed - $!\n" unless close $fh;
190 if (!rename($tmpname, $filename)) {
191 my $msg = "close (rename) atomic file '$filename' failed: $!\n";
197 sub file_get_contents
{
198 my ($filename, $max) = @_;
200 my $fh = IO
::File-
>new($filename, "r") ||
201 die "can't open '$filename' - $!\n";
203 my $content = safe_read_from
($fh, $max);
210 sub file_read_firstline
{
213 my $fh = IO
::File-
>new ($filename, "r");
214 return undef if !$fh;
222 my ($fh, $max, $oneline) = @_;
224 $max = 32768 if !$max;
229 while ($count = sysread($fh, $input, 8192, $br)) {
231 die "input too long - aborting\n" if $br > $max;
232 if ($oneline && $input =~ m/^(.*)\n/) {
237 die "unable to read input - $!\n" if !defined($count);
243 my ($cmd, %param) = @_;
251 # see 'man bash' for option pipefail
252 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
257 $cmdstr = cmd2string
($cmd);
275 foreach my $p (keys %param) {
276 if ($p eq 'timeout') {
277 $timeout = $param{$p};
278 } elsif ($p eq 'umask') {
279 $old_umask = umask($param{$p});
280 } elsif ($p eq 'errmsg') {
281 $errmsg = $param{$p};
282 } elsif ($p eq 'input') {
284 } elsif ($p eq 'output') {
285 $output = $param{$p};
286 } elsif ($p eq 'outfunc') {
287 $outfunc = $param{$p};
288 } elsif ($p eq 'errfunc') {
289 $errfunc = $param{$p};
290 } elsif ($p eq 'logfunc') {
291 $logfunc = $param{$p};
292 } elsif ($p eq 'afterfork') {
293 $afterfork = $param{$p};
295 die "got unknown parameter '$p' for run_command\n";
300 my $origerrfunc = $errfunc;
304 &$origerrfunc("$laststderr\n");
306 print STDERR
"$laststderr\n" if $laststderr;
313 my $reader = $output && $output =~ m/^>&/ ?
$output : IO
::File-
>new();
314 my $writer = $input && $input =~ m/^<&/ ?
$input : IO
::File-
>new();
315 my $error = IO
::File-
>new();
317 # try to avoid locale related issues/warnings
318 my $lang = $param{lang
} || 'C';
323 local $ENV{LC_ALL
} = $lang;
325 # suppress LVM warnings like: "File descriptor 3 left open";
326 local $ENV{LVM_SUPPRESS_FD_WARNINGS
} = "1";
328 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
330 # if we pipe fron STDIN, open3 closes STDIN, so we we
331 # a perl warning "Filehandle STDIN reopened as GENXYZ .. "
332 # as soon as we open a new file.
333 # to avoid that we open /dev/null
334 if (!ref($writer) && !defined(fileno(STDIN
))) {
336 open(STDIN
, "</dev/null");
343 if ($orig_pid != $$) {
351 local $SIG{ALRM
} = sub { die "got timeout\n"; } if $timeout;
352 $oldtimeout = alarm($timeout) if $timeout;
354 &$afterfork() if $afterfork;
357 print $writer $input if defined $input;
361 my $select = new IO
::Select
;
362 $select->add($reader) if ref($reader);
363 $select->add($error);
368 my $starttime = time();
370 while ($select->count) {
371 my @handles = $select->can_read(1);
373 foreach my $h (@handles) {
375 my $count = sysread ($h, $buf, 4096);
376 if (!defined ($count)) {
382 $select->remove ($h) if !$count;
384 if ($outfunc || $logfunc) {
387 while ($outlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
389 &$outfunc($line) if $outfunc;
390 &$logfunc($line) if $logfunc;
403 } elsif ($h eq $error) {
404 if ($errfunc || $logfunc) {
407 while ($errlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
409 &$errfunc($line) if $errfunc;
410 &$logfunc($line) if $logfunc;
427 &$outfunc($outlog) if $outfunc && $outlog;
428 &$logfunc($outlog) if $logfunc && $outlog;
430 &$errfunc($errlog) if $errfunc && $errlog;
431 &$logfunc($errlog) if $logfunc && $errlog;
436 die "failed to execute\n";
437 } elsif (my $sig = ($? & 127)) {
438 die "got signal $sig\n";
439 } elsif (my $ec = ($? >> 8)) {
440 if (!($ec == 24 && ($cmdstr =~ m
|^(\S
+/)?rsync\s
|))) {
441 if ($errmsg && $laststderr) {
442 my $lerr = $laststderr;
446 die "exit code $ec\n";
457 if ($errmsg && $laststderr) {
458 &$errfunc(undef); # flush laststderr
461 umask ($old_umask) if defined($old_umask);
463 alarm($oldtimeout) if $oldtimeout;
466 if ($pid && ($err eq "got timeout\n")) {
469 die "command '$cmdstr' failed: $err";
473 $err =~ s/^usermod:\s*// if $cmdstr =~ m
|^(\S
+/)?usermod\s
|;
476 die "command '$cmdstr' failed: $err";
484 my $listtxt = shift || '';
486 return split (/\0/, $listtxt) if $listtxt =~ m/\0/;
488 $listtxt =~ s/[,;]/ /g;
489 $listtxt =~ s/^\s+//;
491 my @data = split (/\s+/, $listtxt);
499 return $txt if !defined($txt);
507 # simple uri templates like "/vms/{vmid}"
508 sub template_replace
{
509 my ($tmpl, $data) = @_;
511 return $tmpl if !$tmpl;
514 while ($tmpl =~ m/([^{]+)?({([^}]+)})?/g) {
516 $res .= ($data->{$3} || '-') if $2;
522 my ($filename, $fh, $data) = @_;
526 my $res = print $fh $data;
528 die "write to '$filename' failed\n" if !$res;
534 'at' => 'ftp.at.debian.org',
535 'au' => 'ftp.au.debian.org',
536 'be' => 'ftp.be.debian.org',
537 'bg' => 'ftp.bg.debian.org',
538 'br' => 'ftp.br.debian.org',
539 'ca' => 'ftp.ca.debian.org',
540 'ch' => 'ftp.ch.debian.org',
541 'cl' => 'ftp.cl.debian.org',
542 'cz' => 'ftp.cz.debian.org',
543 'de' => 'ftp.de.debian.org',
544 'dk' => 'ftp.dk.debian.org',
545 'ee' => 'ftp.ee.debian.org',
546 'es' => 'ftp.es.debian.org',
547 'fi' => 'ftp.fi.debian.org',
548 'fr' => 'ftp.fr.debian.org',
549 'gr' => 'ftp.gr.debian.org',
550 'hk' => 'ftp.hk.debian.org',
551 'hr' => 'ftp.hr.debian.org',
552 'hu' => 'ftp.hu.debian.org',
553 'ie' => 'ftp.ie.debian.org',
554 'is' => 'ftp.is.debian.org',
555 'it' => 'ftp.it.debian.org',
556 'jp' => 'ftp.jp.debian.org',
557 'kr' => 'ftp.kr.debian.org',
558 'mx' => 'ftp.mx.debian.org',
559 'nl' => 'ftp.nl.debian.org',
560 'no' => 'ftp.no.debian.org',
561 'nz' => 'ftp.nz.debian.org',
562 'pl' => 'ftp.pl.debian.org',
563 'pt' => 'ftp.pt.debian.org',
564 'ro' => 'ftp.ro.debian.org',
565 'ru' => 'ftp.ru.debian.org',
566 'se' => 'ftp.se.debian.org',
567 'si' => 'ftp.si.debian.org',
568 'sk' => 'ftp.sk.debian.org',
569 'tr' => 'ftp.tr.debian.org',
570 'tw' => 'ftp.tw.debian.org',
571 'gb' => 'ftp.uk.debian.org',
572 'us' => 'ftp.us.debian.org',
577 'dk' => ['Danish', 'da', 'qwerty/dk-latin1.kmap.gz', 'dk', 'nodeadkeys'],
578 'de' => ['German', 'de', 'qwertz/de-latin1-nodeadkeys.kmap.gz', 'de', 'nodeadkeys' ],
579 'de-ch' => ['Swiss-German', 'de-ch', 'qwertz/sg-latin1.kmap.gz', 'ch', 'de_nodeadkeys' ],
580 'en-gb' => ['United Kingdom', 'en-gb', 'qwerty/uk.kmap.gz' , 'gb', undef],
581 'en-us' => ['U.S. English', 'en-us', 'qwerty/us-latin1.kmap.gz', 'us', undef ],
582 'es' => ['Spanish', 'es', 'qwerty/es.kmap.gz', 'es', 'nodeadkeys'],
583 #'et' => [], # Ethopia or Estonia ??
584 'fi' => ['Finnish', 'fi', 'qwerty/fi-latin1.kmap.gz', 'fi', 'nodeadkeys'],
585 #'fo' => ['Faroe Islands', 'fo', ???, 'fo', 'nodeadkeys'],
586 'fr' => ['French', 'fr', 'azerty/fr-latin1.kmap.gz', 'fr', 'nodeadkeys'],
587 'fr-be' => ['Belgium-French', 'fr-be', 'azerty/be2-latin1.kmap.gz', 'be', 'nodeadkeys'],
588 'fr-ca' => ['Canada-French', 'fr-ca', 'qwerty/cf.kmap.gz', 'ca', 'fr-legacy'],
589 'fr-ch' => ['Swiss-French', 'fr-ch', 'qwertz/fr_CH-latin1.kmap.gz', 'ch', 'fr_nodeadkeys'],
590 #'hr' => ['Croatia', 'hr', 'qwertz/croat.kmap.gz', 'hr', ??], # latin2?
591 'hu' => ['Hungarian', 'hu', 'qwertz/hu.kmap.gz', 'hu', undef],
592 'is' => ['Icelandic', 'is', 'qwerty/is-latin1.kmap.gz', 'is', 'nodeadkeys'],
593 'it' => ['Italian', 'it', 'qwerty/it2.kmap.gz', 'it', 'nodeadkeys'],
594 'jp' => ['Japanese', 'ja', 'qwerty/jp106.kmap.gz', 'jp', undef],
595 'lt' => ['Lithuanian', 'lt', 'qwerty/lt.kmap.gz', 'lt', 'std'],
596 #'lv' => ['Latvian', 'lv', 'qwerty/lv-latin4.kmap.gz', 'lv', ??], # latin4 or latin7?
597 'mk' => ['Macedonian', 'mk', 'qwerty/mk.kmap.gz', 'mk', 'nodeadkeys'],
598 'nl' => ['Dutch', 'nl', 'qwerty/nl.kmap.gz', 'nl', undef],
599 #'nl-be' => ['Belgium-Dutch', 'nl-be', ?, ?, ?],
600 'no' => ['Norwegian', 'no', 'qwerty/no-latin1.kmap.gz', 'no', 'nodeadkeys'],
601 'pl' => ['Polish', 'pl', 'qwerty/pl.kmap.gz', 'pl', undef],
602 'pt' => ['Portuguese', 'pt', 'qwerty/pt-latin1.kmap.gz', 'pt', 'nodeadkeys'],
603 'pt-br' => ['Brazil-Portuguese', 'pt-br', 'qwerty/br-latin1.kmap.gz', 'br', 'nodeadkeys'],
604 #'ru' => ['Russian', 'ru', 'qwerty/ru.kmap.gz', 'ru', undef], # dont know?
605 'si' => ['Slovenian', 'sl', 'qwertz/slovene.kmap.gz', 'si', undef],
606 'se' => ['Swedish', 'sv', 'qwerty/se-latin1.kmap.gz', 'se', 'nodeadkeys'],
608 'tr' => ['Turkish', 'tr', 'qwerty/trq.kmap.gz', 'tr', undef],
611 my $kvmkeymaparray = [];
612 foreach my $lc (keys %$keymaphash) {
613 push @$kvmkeymaparray, $keymaphash->{$lc}->[1];
621 return $kvmkeymaparray;
625 my ($param, $key) = @_;
627 my $res = $param->{$key};
628 delete $param->{$key};
633 # Note: we use this to wait until vncterm/spiceterm is ready
634 sub wait_for_vnc_port
{
635 my ($port, $timeout) = @_;
637 $timeout = 5 if !$timeout;
639 my $starttime = [gettimeofday
];
642 while (($elapsed = tv_interval
($starttime)) < $timeout) {
643 if (my $fh = IO
::File-
>new ("/proc/net/tcp", "r")) {
644 while (defined (my $line = <$fh>)) {
645 if ($line =~ m/^\s*\d+:\s+([0-9A-Fa-f]{8}):([0-9A-Fa-f]{4})\s/) {
646 if ($port == hex($2)) {
654 $sleeptime += 100000 if $sleeptime < 1000000;
661 sub next_unused_port
{
662 my ($range_start, $range_end) = @_;
664 # We use a file to register allocated ports.
665 # Those registrations expires after $expiretime.
666 # We use this to avoid race conditions between
667 # allocation and use of ports.
669 my $filename = "/var/tmp/pve-reserved-ports";
678 if (my $fh = IO
::File-
>new ($filename, "r")) {
679 while (my $line = <$fh>) {
680 if ($line =~ m/^(\d+)\s(\d+)$/) {
681 my ($port, $timestamp) = ($1, $2);
682 if (($timestamp + $expiretime) > $ctime) {
683 $ports->{$port} = $timestamp; # not expired
691 for (my $p = $range_start; $p < $range_end; $p++) {
692 next if $ports->{$p}; # reserved
694 my $sock = IO
::Socket
::INET-
>new(Listen
=> 5,
695 LocalAddr
=> '0.0.0.0',
703 $ports->{$p} = $ctime;
709 foreach my $p (keys %$ports) {
710 $data .= "$p $ports->{$p}\n";
713 file_set_contents
($filename, $data);
718 my $p = lock_file
($filename, 10, $code);
721 die "unable to find free port (${range_start}-${range_end})\n" if !$p;
726 sub next_migrate_port
{
727 return next_unused_port
(60000, 60010);
731 return next_unused_port
(5900, 6000);
734 sub next_spice_port
{
735 return next_unused_port
(61000, 61099);
738 # NOTE: NFS syscall can't be interrupted, so alarm does
739 # not work to provide timeouts.
740 # from 'man nfs': "Only SIGKILL can interrupt a pending NFS operation"
741 # So the spawn external 'df' process instead of using
742 # Filesys::Df (which uses statfs syscall)
744 my ($path, $timeout) = @_;
746 my $cmd = [ 'df', '-P', '-B', '1', $path];
756 if (my ($fsid, $total, $used, $avail) = $line =~
757 m/^(\S+.*)\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s.*$/) {
765 eval { run_command
($cmd, timeout
=> $timeout, outfunc
=> $parser); };
772 # We use this to uniquely identify a process.
773 # An 'Unique Process ID' has the following format:
774 # "UPID:$node:$pid:$pstart:$startime:$dtype:$id:$user"
779 # Note: pstart can be > 32bit if uptime > 497 days, so this can result in
780 # more that 8 characters for pstart
781 return sprintf("UPID:%s:%08X:%08X:%08X:%s:%s:%s:", $d->{node
}, $d->{pid
},
782 $d->{pstart
}, $d->{starttime
}, $d->{type
}, $d->{id
},
787 my ($upid, $noerr) = @_;
792 # "UPID:$node:$pid:$pstart:$startime:$dtype:$id:$user"
793 # Note: allow up to 9 characters for pstart (work until 20 years uptime)
794 if ($upid =~ m/^UPID:([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/) {
796 $res->{pid
} = hex($3);
797 $res->{pstart
} = hex($4);
798 $res->{starttime
} = hex($5);
803 my $subdir = substr($5, 7, 8);
804 $filename = "$pvetaskdir/$subdir/$upid";
807 return undef if $noerr;
808 die "unable to parse worker upid '$upid'\n";
811 return wantarray ?
($res, $filename) : $res;
817 my ($task, $filename) = upid_decode
($upid);
819 my $dirname = dirname
($filename);
822 my $wwwid = getpwnam('www-data') ||
823 die "getpwnam failed";
827 my $outfh = IO
::File-
>new ($filename, O_WRONLY
|O_CREAT
|O_EXCL
, $perm) ||
828 die "unable to create output file '$filename' - $!\n";
829 chown $wwwid, -1, $outfh;
834 sub upid_read_status
{
837 my ($task, $filename) = upid_decode
($upid);
838 my $fh = IO
::File-
>new($filename, "r");
839 return "unable to open file - $!" if !$fh;
841 sysseek($fh, -$maxlen, 2);
843 my $br = sysread($fh, $readbuf, $maxlen);
846 return "unable to extract last line"
847 if $readbuf !~ m/\n?(.+)$/;
849 if ($line =~ m/^TASK OK$/) {
851 } elsif ($line =~ m/^TASK ERROR: (.+)$/) {
854 return "unexpected status";
857 return "unable to read tail (got $br bytes)";
860 # useful functions to store comments in config files
864 # all control and hi-bit characters, and ':'
865 my $unsafe = "^\x20-\x39\x3b-\x7e";
866 return uri_escape
(Encode
::encode
("utf8", $text), $unsafe);
872 return Encode
::decode
("utf8", uri_unescape
($data));
875 sub decode_utf8_parameters
{
878 foreach my $p (qw(comment description firstname lastname)) {
879 $param->{$p} = decode
('utf8', $param->{$p}) if $param->{$p};
885 sub random_ether_addr
{
887 my ($seconds, $microseconds) = gettimeofday
;
889 my $rand = Digest
::SHA
::sha1_hex
($$, rand(), $seconds, $microseconds);
892 for (my $i = 0; $i < 6; $i++) {
893 my $ss = hex(substr($rand, $i*2, 2));
895 $ss &= 0xfe; # clear multicast
896 $ss |= 2; # set local id
898 $ss = sprintf("%02X", $ss);
913 return String
::ShellQuote
::shell_quote
($str);
919 die "no arguments" if !$cmd;
921 return $cmd if !ref($cmd);
924 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
926 return join (' ', @qa);
929 # split an shell argument string into an array,
933 return $str ?
[ Text
::ParseWords
::shellwords
($str) ] : [];
937 my ($filename, $start, $limit, $filter) = @_;
942 my $fh = IO
::File-
>new($filename, "r");
945 push @$lines, { n
=> $count, t
=> "unable to open file - $!"};
946 return ($count, $lines);
949 $start = 0 if !$start;
950 $limit = 50 if !$limit;
955 # duplicate code, so that we do not slow down normal path
956 while (defined($line = <$fh>)) {
957 next if $line !~ m/$filter/;
958 next if $count++ < $start;
961 push @$lines, { n
=> $count, t
=> $line};
965 while (defined($line = <$fh>)) {
966 next if $count++ < $start;
969 push @$lines, { n
=> $count, t
=> $line};
976 # HACK: ExtJS store.guaranteeRange() does not like empty array
980 push @$lines, { n
=> $count, t
=> "no content"};
983 return ($count, $lines);
987 my ($dir, $regex) = @_;
989 my $dh = IO
::Dir-
>new ($dir);
990 return wantarray ?
() : undef if !$dh;
992 while (defined(my $tmp = $dh->read)) {
993 if (my @res = $tmp =~ m/^($regex)$/) {
995 return wantarray ?
@res : $tmp;
1000 return wantarray ?
() : undef;
1003 sub dir_glob_foreach
{
1004 my ($dir, $regex, $func) = @_;
1006 my $dh = IO
::Dir-
>new ($dir);
1008 while (defined(my $tmp = $dh->read)) {
1009 if (my @res = $tmp =~ m/^($regex)$/) {
1016 sub assert_if_modified
{
1017 my ($digest1, $digest2) = @_;
1019 if ($digest1 && $digest2 && ($digest1 ne $digest2)) {
1020 die "detected modified configuration - file changed by other user? Try again.\n";
1024 # Digest for short strings
1025 # like FNV32a, but we only return 31 bits (positive numbers)
1029 my $hval = 0x811c9dc5;
1031 foreach my $c (unpack('C*', $string)) {
1039 $hval = $hval & 0xffffffff;
1041 return $hval & 0x7fffffff;
1044 sub fnv31a_hex
{ return sprintf("%X", fnv31a
(@_)); }