communicator/ssh: use SetExited

This commit is contained in:
Mitchell Hashimoto 2013-07-29 12:12:42 -07:00
parent 1400645d69
commit 1812efe3b5
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() { go func() {
defer session.Close() defer session.Close()
err := session.Wait() err := session.Wait()
cmd.ExitStatus = 0 exitStatus := 0
if err != nil { if err != nil {
exitErr, ok := err.(*ssh.ExitError) exitErr, ok := err.(*ssh.ExitError)
if ok { if ok {
cmd.ExitStatus = exitErr.ExitStatus() exitStatus = exitErr.ExitStatus()
} }
} }
cmd.Exited = true cmd.SetExited(exitStatus)
}() }()
return return

View File

@ -34,7 +34,7 @@ type RemoteCmd struct {
ExitStatus int ExitStatus int
// Internal locks and such used for safely setting some shared variables // Internal locks and such used for safely setting some shared variables
l sync.Mutex l sync.Mutex
exitCond *sync.Cond exitCond *sync.Cond
} }

View File

@ -8,7 +8,6 @@ import (
"log" "log"
"net" "net"
"net/rpc" "net/rpc"
"time"
) )
// An implementation of packer.Communicator where the communicator is actually // 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() defer conn.Close()
} }
for !cmd.Exited { cmd.Wait()
time.Sleep(50 * time.Millisecond)
}
responseWriter.Encode(&CommandFinished{cmd.ExitStatus}) 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") assert.Equal(data, "infoo\n", "should be correct stdin")
// Test that we can get the exit status properly // Test that we can get the exit status properly
c.startCmd.ExitStatus = 42 c.startCmd.SetExited(42)
c.startCmd.Exited = true
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
if cmd.Exited { if cmd.Exited {