use Digest::SHA;
use Text::ParseWords;
use String::ShellQuote;
+use Time::HiRes qw(usleep gettimeofday tv_interval);
our @EXPORT_OK = qw(
$IPV6RE
return $res;
}
-# Note: we use this to wait until vncterm is ready
+# Note: we use this to wait until vncterm/spiceterm is ready
sub wait_for_vnc_port {
my ($port, $timeout) = @_;
$timeout = 5 if !$timeout;
+ my $sleeptime = 0;
+ my $starttime = [gettimeofday];
+ my $elapsed;
- for (my $i = 0; $i < $timeout; $i++) {
+ while (($elapsed = tv_interval($starttime)) < $timeout) {
if (my $fh = IO::File->new ("/proc/net/tcp", "r")) {
while (defined (my $line = <$fh>)) {
if ($line =~ m/^\s*\d+:\s+([0-9A-Fa-f]{8}):([0-9A-Fa-f]{4})\s/) {
}
close($fh);
}
- sleep(1);
+ $sleeptime += 100000 if $sleeptime < 1000000;
+ usleep($sleeptime);
}
return undef;
return next_unused_port(5900, 6000);
}
+sub next_spice_port {
+ return next_unused_port(61000, 61099);
+}
+
# NOTE: NFS syscall can't be interrupted, so alarm does
# not work to provide timeouts.
# from 'man nfs': "Only SIGKILL can interrupt a pending NFS operation"
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++) {
}
sub dump_logfile {
- my ($filename, $start, $limit) = @_;
+ my ($filename, $start, $limit, $filter) = @_;
my $lines = [];
my $count = 0;
$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);
}
}
+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;