From 9b0c3b28c57dde3b18b147e3ad260e81f2f86ec2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jul 2013 12:12:42 -0700 Subject: [PATCH] communicator/ssh: use SetExited --- communicator/ssh/communicator.go | 6 +++--- packer/communicator.go | 2 +- packer/rpc/communicator.go | 6 +----- packer/rpc/communicator_test.go | 3 +-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 67d21aa6a..3af09e1d0 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -79,15 +79,15 @@ func (c *comm) Start(cmd *packer.RemoteCmd) (err error) { go func() { defer session.Close() err := session.Wait() - cmd.ExitStatus = 0 + exitStatus := 0 if err != nil { exitErr, ok := err.(*ssh.ExitError) if ok { - cmd.ExitStatus = exitErr.ExitStatus() + exitStatus = exitErr.ExitStatus() } } - cmd.Exited = true + cmd.SetExited(exitStatus) }() return diff --git a/packer/communicator.go b/packer/communicator.go index 4c8c5cce2..63c052125 100644 --- a/packer/communicator.go +++ b/packer/communicator.go @@ -34,7 +34,7 @@ type RemoteCmd struct { ExitStatus int // Internal locks and such used for safely setting some shared variables - l sync.Mutex + l sync.Mutex exitCond *sync.Cond } diff --git a/packer/rpc/communicator.go b/packer/rpc/communicator.go index 44132250f..c6971a9d7 100644 --- a/packer/rpc/communicator.go +++ b/packer/rpc/communicator.go @@ -8,7 +8,6 @@ import ( "log" "net" "net/rpc" - "time" ) // An implementation of packer.Communicator where the communicator is actually @@ -203,10 +202,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface defer conn.Close() } - for !cmd.Exited { - time.Sleep(50 * time.Millisecond) - } - + cmd.Wait() responseWriter.Encode(&CommandFinished{cmd.ExitStatus}) }() diff --git a/packer/rpc/communicator_test.go b/packer/rpc/communicator_test.go index 003c78473..52867a8e2 100644 --- a/packer/rpc/communicator_test.go +++ b/packer/rpc/communicator_test.go @@ -96,8 +96,7 @@ func TestCommunicatorRPC(t *testing.T) { assert.Equal(data, "infoo\n", "should be correct stdin") // Test that we can get the exit status properly - c.startCmd.ExitStatus = 42 - c.startCmd.Exited = true + c.startCmd.SetExited(42) for i := 0; i < 5; i++ { if cmd.Exited {