Skip to content

Commit

Permalink
Use Go's cross-platform process killing instead of the UNIX-only sysc…
Browse files Browse the repository at this point in the history
…all.Kill
  • Loading branch information
hsluoyz authored and ilackarms committed Jun 25, 2018
1 parent 1e0e09b commit c5c126a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 10 additions & 3 deletions pkg/providers/qemu/stop_instance_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
package qemu

import (
"os"
"strconv"
"syscall"

"github.com/Sirupsen/logrus"
"github.com/emc-advanced-dev/pkg/errors"
"github.com/solo-io/unik/pkg/types"
"strconv"
)

func (p *QemuProvider) StopInstance(id string) error {
Expand All @@ -23,9 +24,15 @@ func (p *QemuProvider) StopInstance(id string) error {
return errors.New("invalid instance id (should be qemu pid)", err)
}

if err := syscall.Kill(pid, syscall.SIGKILL); err != nil {
logrus.Warn("failed terminating instance, assuming instance has externally terminated", err)
process, err := os.FindProcess(pid)
if err != nil {
logrus.Warn("failed finding instance, assuming instance has externally terminated", err)
} else {
if err := process.Signal(syscall.SIGKILL); err != nil {
logrus.Warn("failed terminating instance, assuming instance has externally terminated", err)
}
}

volumesToDetach := []*types.Volume{}
volumes, err := p.ListVolumes()
if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions pkg/providers/ukvm/stop_instance_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
package ukvm

import (
"os"
"strconv"
"syscall"

"github.com/Sirupsen/logrus"
"github.com/emc-advanced-dev/pkg/errors"
"github.com/solo-io/unik/pkg/types"
"strconv"
)

func (p *UkvmProvider) StopInstance(id string) error {
Expand All @@ -23,9 +24,15 @@ func (p *UkvmProvider) StopInstance(id string) error {
return errors.New("invalid instance id (should be ukvm pid)", err)
}

if err := syscall.Kill(pid, syscall.SIGKILL); err != nil {
logrus.Warn("failed terminating instance, assuming instance has externally terminated", err)
process, err := os.FindProcess(pid)
if err != nil {
logrus.Warn("failed finding instance, assuming instance has externally terminated", err)
} else {
if err := process.Signal(syscall.SIGKILL); err != nil {
logrus.Warn("failed terminating instance, assuming instance has externally terminated", err)
}
}

volumesToDetach := []*types.Volume{}
volumes, err := p.ListVolumes()
if err != nil {
Expand Down

0 comments on commit c5c126a

Please sign in to comment.