From 09c75ba216ab522f6fc2e974e6e8768933d0ddd4 Mon Sep 17 00:00:00 2001 From: Robin Elfrink Date: Tue, 30 Jul 2024 13:13:08 +0200 Subject: [PATCH] fix: reset change state after power operation According to https://github.com/vmware/open-vm-tools/blob/stable-12.4.5/open-vm-tools/services/plugins/powerOps/powerOps.c#L225, after power operations we need to reset the state to GUESTOS_STATECHANGE_NONE. Signed-off-by: Robin Elfrink --- internal/tboxcmds/power.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/tboxcmds/power.go b/internal/tboxcmds/power.go index a2f3dcf..ae3da71 100644 --- a/internal/tboxcmds/power.go +++ b/internal/tboxcmds/power.go @@ -10,7 +10,7 @@ import ( // vmware/guestrpc/powerops.h. const ( - _ = iota + PowerStateNone = iota PowerStateHalt PowerStateReboot PowerStatePowerOn @@ -52,6 +52,12 @@ func (op powerOp) HandleCommand([]byte) ([]byte, error) { rc := nanotoolbox.RpciOK + // Let the host know we're considering the state change + msg := fmt.Sprintf("tools.os.statechange.status %s%d\x00", rc, op.state) + if _, err := op.out.Request([]byte(msg)); err != nil { + return nil, fmt.Errorf("error sending %q: %w", msg, err) + } + if op.handler != nil { if err := op.handler(); err != nil { l.WithError(err).Error("error handling power operation") @@ -60,7 +66,8 @@ func (op powerOp) HandleCommand([]byte) ([]byte, error) { } } - msg := fmt.Sprintf("tools.os.statechange.status %s%d\x00", rc, op.state) + // Send the result and reset the state change + msg = fmt.Sprintf("tools.os.statechange.status %s%d\x00", rc, PowerStateNone) if _, err := op.out.Request([]byte(msg)); err != nil { return nil, fmt.Errorf("error sending %q: %w", msg, err) }