Commit c8079a42 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: client kill waits for logging to complete

parent e1785e42
...@@ -14,12 +14,14 @@ import ( ...@@ -14,12 +14,14 @@ import (
type client struct { type client struct {
cmd *exec.Cmd cmd *exec.Cmd
exited bool exited bool
doneLogging bool
} }
func NewClient(cmd *exec.Cmd) *client { func NewClient(cmd *exec.Cmd) *client {
return &client{ return &client{
cmd, cmd,
false, false,
false,
} }
} }
...@@ -104,6 +106,18 @@ func (c *client) Start() (address string, err error) { ...@@ -104,6 +106,18 @@ func (c *client) Start() (address string, err error) {
func (c *client) Kill() { func (c *client) Kill() {
c.cmd.Process.Kill() c.cmd.Process.Kill()
// Wait for the client to finish logging so we have a complete log
done := make(chan bool)
go func() {
for !c.doneLogging {
time.Sleep(10 * time.Millisecond)
}
done <- true
}()
<-done
} }
func (c *client) logStderr(r io.Reader) { func (c *client) logStderr(r io.Reader) {
...@@ -125,4 +139,7 @@ func (c *client) logStderr(r io.Reader) { ...@@ -125,4 +139,7 @@ func (c *client) logStderr(r io.Reader) {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
} }
// Flag that we've completed logging for others
c.doneLogging = true
} }
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