Commit 68a024b5 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: Make sure subprocess properly dies if error

parent 2ff1fabb
......@@ -11,7 +11,25 @@ import (
"time"
)
// Returns a valid packer.Command where the command is executed via RPC
// to a plugin that is within a subprocess.
//
// This method will start the given exec.Cmd, which should point to
// the plugin binary to execute. Some configuration will be done to
// the command, such as overriding Stdout and some environmental variables.
//
// 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",
......
......@@ -6,6 +6,7 @@ import (
"testing"
)
// TODO: Test command cleanup functionality
// TODO: Test timeout functionality
func TestCommand_NoExist(t *testing.T) {
......
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