Commit 70d378b9 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: Better command cleanup

parent 68a024b5
...@@ -20,16 +20,6 @@ import ( ...@@ -20,16 +20,6 @@ import (
// //
// This function guarantees the subprocess will end in a timely manner. // This function guarantees the subprocess will end in a timely manner.
func Command(cmd *exec.Cmd) (result packer.Command, err error) { 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{ env := []string{
"PACKER_PLUGIN_MIN_PORT=10000", "PACKER_PLUGIN_MIN_PORT=10000",
"PACKER_PLUGIN_MAX_PORT=25000", "PACKER_PLUGIN_MAX_PORT=25000",
...@@ -43,6 +33,14 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) { ...@@ -43,6 +33,14 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) {
return 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 // Goroutine + channel to signal that the process exited
cmdExited := make(chan bool) cmdExited := make(chan bool)
go func() { go func() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment