Skip to content

Commit

Permalink
Merge pull request #8 from AntonioMeireles/crasher_fixes
Browse files Browse the repository at this point in the history
crasher fixes
  • Loading branch information
AntonioMeireles committed Dec 1, 2015
2 parents 9d0387c + 9e59ef9 commit 4e0eaa1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 11 additions & 1 deletion halt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"os"
"time"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -85,7 +86,16 @@ func (vm VMInfo) halt() (err error) {
}
}
}
log.Printf("successfully halted '%s'\n", vm.Name)
// wait until it's _really_ dead
defer func() {
for range time.Tick(500 * time.Millisecond) {
if _, ee := os.FindProcess(vm.Pid); ee == nil {
break
}
}
log.Printf("successfully halted '%s'\n", vm.Name)
}()

return
}

Expand Down
9 changes: 6 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/blang/semver"
"github.com/mitchellh/go-ps"
Expand Down Expand Up @@ -338,9 +339,11 @@ func (vm *VMInfo) metadataService() (endpoint string, err error) {
free net.Listener
runOnce sync.Once
)

if free, err = net.Listen("tcp", "localhost:0"); err != nil {
return
// workaround OSX and/or golang weirdness...
for range time.Tick(500 * time.Millisecond) {
if free, err = net.Listen("tcp", "localhost:0"); err == nil {
break
}
}

mux := http.NewServeMux()
Expand Down
8 changes: 4 additions & 4 deletions uuid2ip/uuid2ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ func GuestMACfromUUID(uuid string) (mac string, err error) {
macC, failC := C.CString(mac), C.CString(fail)
var ret C.int

runtime.LockOSThread()
defer func() {
C.free(unsafe.Pointer(uuidC))
C.free(unsafe.Pointer(macC))
C.free(unsafe.Pointer(failC))
runtime.UnlockOSThread()
}()

runtime.LockOSThread()
defer runtime.UnlockOSThread()

if ret = C.vmnet_get_mac_address_from_uuid(uuidC,
(*C.char)(unsafe.Pointer(macC)),
(*C.char)(unsafe.Pointer(failC))); ret != 0 {
return mac, fmt.Errorf(C.GoString(failC))
}
return C.GoString(macC), nil
mac = C.GoString(macC)
return mac, nil
}

// GuestIPfromMAC returns the IP address that would be leased to the given MAC
Expand Down

0 comments on commit 4e0eaa1

Please sign in to comment.