communicator/ssh: use SetExited

This commit is contained in:
Mitchell Hashimoto 2013-07-29 12:12:42 -07:00
parent 333ed6aa78
commit 9b0c3b28c5
4 changed files with 6 additions and 11 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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})
}()

View File

@ -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 {