packer/plugin: use chan struct{} for condition variable behavior
This commit is contained in:
parent
31731414be
commit
ce0322662d
@ -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() {
|
|||||||
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) {
|
|||||||
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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user