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