mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-05 12:46:25 +00:00
swtpm: wait for pidfile
swtpm may take a little bit to daemonize, so the pidfile might not be available right after run_command. Causes an ugly warning about using an undefined value in a match, so wait up to 5s for it to appear. Note that in testing this loop only ever got to the first or second iteration, so I believe the timeout duration should be more than enough. Also add a missing 'usleep' import, 'usleep' was used before but never imported, apparently the other case never got triggered... Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
parent
9d83932d7c
commit
f85951dc82
@ -22,7 +22,7 @@ use JSON;
|
||||
use MIME::Base64;
|
||||
use POSIX;
|
||||
use Storable qw(dclone);
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
use Time::HiRes qw(gettimeofday usleep);
|
||||
use URI::Escape;
|
||||
use UUID;
|
||||
|
||||
@ -3058,6 +3058,14 @@ sub start_swtpm {
|
||||
push @$emulator_cmd, "--tpm2" if $tpm->{version} eq 'v2.0';
|
||||
run_command($emulator_cmd, outfunc => sub { print $1; });
|
||||
|
||||
# swtpm may take a bit to start before daemonizing, wait up to 5s for pid
|
||||
my $tries = 100;
|
||||
while (! -e $paths->{pid}) {
|
||||
usleep(50000);
|
||||
die "failed to start swtpm: pid file '$paths->{pid}' wasn't created.\n"
|
||||
if --$tries == 0;
|
||||
}
|
||||
|
||||
# return untainted PID of swtpm daemon so it can be killed on error
|
||||
file_read_firstline($paths->{pid}) =~ m/(\d+)/;
|
||||
return $1;
|
||||
|
Loading…
Reference in New Issue
Block a user