Commit 9b0c3b28 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

communicator/ssh: use SetExited

parent 333ed6aa
...@@ -79,15 +79,15 @@ func (c *comm) Start(cmd *packer.RemoteCmd) (err error) { ...@@ -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
......
...@@ -34,7 +34,7 @@ type RemoteCmd struct { ...@@ -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
} }
......
...@@ -8,7 +8,6 @@ import ( ...@@ -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 ...@@ -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})
}() }()
......
...@@ -96,8 +96,7 @@ func TestCommunicatorRPC(t *testing.T) { ...@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment