Commit 69a5e83f authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: use chan struct{} for condition variable behavior

parent 0dd4a4d8
......@@ -28,7 +28,7 @@ var managedClients = make([]*Client, 0, 5)
type Client struct {
config *ClientConfig
exited bool
doneLogging bool
doneLogging chan struct{}
l sync.Mutex
address string
}
......@@ -188,16 +188,7 @@ func (c *Client) Kill() {
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
<-c.doneLogging
}
// Starts the underlying subprocess, communicating with it to negotiate
......@@ -214,6 +205,8 @@ func (c *Client) Start() (address string, err error) {
return c.address, nil
}
c.doneLogging = make(chan struct{})
env := []string{
fmt.Sprintf("%s=%s", MagicCookieKey, MagicCookieValue),
fmt.Sprintf("PACKER_PLUGIN_MIN_PORT=%d", c.config.MinPort),
......@@ -314,7 +307,7 @@ func (c *Client) logStderr(r io.Reader) {
}
// Flag that we've completed logging for others
c.doneLogging = true
close(c.doneLogging)
}
func (c *Client) rpcClient() (*rpc.Client, error) {
......
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