provisioner/shell: Properly handle closed channels in select
This commit is contained in:
parent
6bcd5de6f5
commit
ffcb7afbee
|
@ -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:
|
||||||
ui.Say(output)
|
if !ok {
|
||||||
case output := <-stdout:
|
stderr = nil
|
||||||
ui.Say(output)
|
} else {
|
||||||
|
ui.Say(output)
|
||||||
|
}
|
||||||
|
case output, ok := <-stdout:
|
||||||
|
if !ok {
|
||||||
|
stdout = nil
|
||||||
|
} else {
|
||||||
|
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.
|
||||||
for output := range stdout {
|
if stdout != nil {
|
||||||
ui.Say(output)
|
for output := range stdout {
|
||||||
|
ui.Say(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for output := range stderr {
|
if stderr != nil {
|
||||||
ui.Say(output)
|
for output := range stderr {
|
||||||
|
ui.Say(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue