Skip to content

Commit

Permalink
fix: reset change state after power operation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
robinelfrink committed Jul 30, 2024
1 parent fce1dc5 commit 09c75ba
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/tboxcmds/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// vmware/guestrpc/powerops.h.
const (
_ = iota
PowerStateNone = iota
PowerStateHalt
PowerStateReboot
PowerStatePowerOn
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down

0 comments on commit 09c75ba

Please sign in to comment.