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) }