packer/plugin: Better command cleanup

This commit is contained in:
Mitchell Hashimoto 2013-05-07 19:48:14 -07:00
parent 68a024b59a
commit 70d378b936
1 changed files with 8 additions and 10 deletions

View File

@ -20,16 +20,6 @@ import (
//
// This function guarantees the subprocess will end in a timely manner.
func Command(cmd *exec.Cmd) (result packer.Command, err error) {
// Make sure the command is properly cleaned up in the case of
// an error.
defer func() {
if err != nil {
if cmd.Process != nil {
cmd.Process.Kill()
}
}
}()
env := []string{
"PACKER_PLUGIN_MIN_PORT=10000",
"PACKER_PLUGIN_MAX_PORT=25000",
@ -43,6 +33,14 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) {
return
}
// Make sure the command is properly cleaned up in the case of
// an error.
defer func() {
if err != nil {
cmd.Process.Kill()
}
}()
// Goroutine + channel to signal that the process exited
cmdExited := make(chan bool)
go func() {