Skip to content

Commit

Permalink
lxd: Make VM shutdown/reboot exit cleanly
Browse files Browse the repository at this point in the history
Closes lxc/incus#256

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
License: Apache-2.0
  • Loading branch information
stgraber authored and hamistao committed Aug 5, 2024
1 parent 67d841a commit 536223c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lxd/instance_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/canonical/lxd/lxd/cluster"
"github.com/canonical/lxd/lxd/db/operationtype"
"github.com/canonical/lxd/lxd/instance"
"github.com/canonical/lxd/lxd/instance/drivers"
"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/lxd/operations"
"github.com/canonical/lxd/lxd/request"
Expand All @@ -35,6 +36,26 @@ import (
"github.com/canonical/lxd/shared/tcp"
"github.com/canonical/lxd/shared/version"
"github.com/canonical/lxd/shared/ws"
// internalInstance "github.com/lxc/incus/internal/instance"
// "github.com/lxc/incus/internal/jmap"
// "github.com/lxc/incus/internal/linux"
// "github.com/lxc/incus/internal/server/cluster"
// "github.com/lxc/incus/internal/server/db/operationtype"
// "github.com/lxc/incus/internal/server/instance"
// "github.com/lxc/incus/internal/server/instance/drivers"
// "github.com/lxc/incus/internal/server/instance/instancetype"
// "github.com/lxc/incus/internal/server/operations"
// "github.com/lxc/incus/internal/server/request"
// "github.com/lxc/incus/internal/server/response"
// "github.com/lxc/incus/internal/server/state"
// internalUtil "github.com/lxc/incus/internal/util"
// "github.com/lxc/incus/internal/version"
// "github.com/lxc/incus/shared/api"
// "github.com/lxc/incus/shared/cancel"
// "github.com/lxc/incus/shared/logger"
// "github.com/lxc/incus/shared/tcp"
// "github.com/lxc/incus/shared/util"
// "github.com/lxc/incus/shared/ws"
)

const execWSControl = -1
Expand Down Expand Up @@ -289,7 +310,14 @@ func (s *execWs) Do(op *operations.Operation) error {
_ = pty.Close()
}

// Make VM disconnections (shutdown/reboot) match containers.
if cmdErr == drivers.ErrExecDisconnected {
cmdResult = 129
cmdErr = nil
}

metadata := shared.Jmap{"return": cmdResult}

err = op.ExtendMetadata(metadata)
if err != nil {
return err
Expand Down

0 comments on commit 536223c

Please sign in to comment.