From 8034e91ca3948710f194113e717f6059dbd0f717 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 1 Jun 2013 17:45:57 -0700 Subject: [PATCH] packer: Lock in RemoteCommand.ExitChan --- packer/communicator.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packer/communicator.go b/packer/communicator.go index 6ca2957c1..7092d5d8e 100644 --- a/packer/communicator.go +++ b/packer/communicator.go @@ -2,6 +2,7 @@ package packer import ( "io" + "sync" "time" ) @@ -34,6 +35,8 @@ type RemoteCommand struct { Stderr io.Reader Exited bool ExitStatus int + + exitChanLock sync.Mutex } // StdoutStream returns a channel that will be sent all the output @@ -47,9 +50,11 @@ func (r *RemoteCommand) StdoutChan() (<-chan string) { // the process exits. This can be used in cases such a select statement // waiting on the process to end. func (r *RemoteCommand) ExitChan() (<-chan int) { - // TODO(mitchellh): lock // TODO(mitchellh): Something more efficient than multiple Wait() calls + r.exitChanLock.Lock() + defer r.exitChanLock.Unlock() + // Make a single buffered channel so that the send doesn't block. exitChan := make(chan int, 1)