[pve-devel] [PATCH qemu-server v3 2/4] add create and remove reboot trigger subs

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Sep 10 14:59:29 CEST 2019


On 06.09.19 14:24, Dominik Csapak wrote:
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> changes from  v2:
> * renamed to clear/create_reboot_request
>  PVE/QemuServer.pm | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index a424720..535297d 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -7401,6 +7401,26 @@ sub nbd_stop {
>      vm_mon_cmd($vmid, 'nbd-server-stop');
>  }
>  
> +sub create_reboot_request {
> +    my ($vmid) = @_;
> +    open(my $fh, '>', "/run/qemu-server/$vmid.reboot")
> +	or die "failed to create reboot trigger file: $!\n";
> +    close($fh);
> +}
> +
> +sub clear_reboot_request {
> +    my ($vmid) = @_;
> +    my $path = "/run/qemu-server/$vmid.reboot";
> +    my $res = 0;
> +
> +    if (-e $path) {
> +	$res = unlink($path);
> +	die "could not remove reboot request for $vmid: $!" if !$res;

this is racy..

Maybe
use POSIX qw(ENOENT);

...

$res = unlink($path);
die "could not remove reboot request for $vmid: $!" if !$res && $! != ENOENT;

?

> +    }
> +
> +    return $res;
> +}
> +
>  # bash completion helper
>  
>  sub complete_backup_archives {
> 





More information about the pve-devel mailing list