Commit ffcb7afb authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

provisioner/shell: Properly handle closed channels in select

parent 6bcd5de6
...@@ -64,25 +64,38 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) { ...@@ -64,25 +64,38 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
stderr := cmd.StderrChan() stderr := cmd.StderrChan()
stdout := cmd.StdoutChan() stdout := cmd.StdoutChan()
OutputLoop:
for { for {
select { select {
case output := <-stderr: case output, ok := <-stderr:
if !ok {
stderr = nil
} else {
ui.Say(output) ui.Say(output)
case output := <-stdout: }
case output, ok := <-stdout:
if !ok {
stdout = nil
} else {
ui.Say(output) ui.Say(output)
}
case exitStatus := <-exit: case exitStatus := <-exit:
log.Printf("shell provisioner exited with status %d", exitStatus) log.Printf("shell provisioner exited with status %d", exitStatus)
break break OutputLoop
} }
} }
// Make sure we finish off stdout/stderr because we may have gotten // Make sure we finish off stdout/stderr because we may have gotten
// a message from the exit channel first. // a message from the exit channel first.
if stdout != nil {
for output := range stdout { for output := range stdout {
ui.Say(output) ui.Say(output)
} }
}
if stderr != nil {
for output := range stderr { for output := range stderr {
ui.Say(output) ui.Say(output)
} }
}
} }
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