Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
ace53450
Commit
ace53450
authored
Jun 01, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: More efficient RemoteCommand.ExitChan
parent
c6dd5476
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
28 deletions
+49
-28
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+4
-5
packer/communicator.go
packer/communicator.go
+33
-11
packer/rpc/communicator.go
packer/rpc/communicator.go
+4
-4
packer/rpc/communicator_test.go
packer/rpc/communicator_test.go
+4
-4
packer/rpc/ui_test.go
packer/rpc/ui_test.go
+2
-2
plugin/provisioner-shell/main.go
plugin/provisioner-shell/main.go
+1
-1
provisioner/shell/provisioner_test.go
provisioner/shell/provisioner_test.go
+1
-1
No files found.
communicator/ssh/communicator.go
View file @
ace53450
...
@@ -153,7 +153,6 @@ func (c *comm) Upload(path string, input io.Reader) error {
...
@@ -153,7 +153,6 @@ func (c *comm) Upload(path string, input io.Reader) error {
return
err
return
err
}
}
log
.
Printf
(
"scp stdout (length %d): %#v"
,
stdout
.
Len
(),
stdout
.
Bytes
())
log
.
Printf
(
"scp stdout (length %d): %#v"
,
stdout
.
Len
(),
stdout
.
Bytes
())
log
.
Printf
(
"scp stderr (length %d): %s"
,
stderr
.
Len
(),
stderr
.
String
())
log
.
Printf
(
"scp stderr (length %d): %s"
,
stderr
.
Len
(),
stderr
.
String
())
...
...
packer/communicator.go
View file @
ace53450
...
@@ -2,6 +2,7 @@ package packer
...
@@ -2,6 +2,7 @@ package packer
import
(
import
(
"io"
"io"
"log"
"sync"
"sync"
"time"
"time"
)
)
...
@@ -36,34 +37,55 @@ type RemoteCommand struct {
...
@@ -36,34 +37,55 @@ type RemoteCommand struct {
Exited
bool
Exited
bool
ExitStatus
int
ExitStatus
int
exitChans
[]
chan
<-
int
exitChanLock
sync
.
Mutex
exitChanLock
sync
.
Mutex
}
}
// StdoutStream returns a channel that will be sent all the output
// StdoutStream returns a channel that will be sent all the output
// of stdout as it comes. The output isn't guaranteed to be a full line.
// of stdout as it comes. The output isn't guaranteed to be a full line.
// When the channel is closed, the process is exited.
// When the channel is closed, the process is exited.
func
(
r
*
RemoteCommand
)
StdoutChan
()
(
<-
chan
string
)
{
func
(
r
*
RemoteCommand
)
StdoutChan
()
<-
chan
string
{
return
nil
return
nil
}
}
// ExitChan returns a channel that will be sent the exit status once
// ExitChan returns a channel that will be sent the exit status once
// the process exits. This can be used in cases such a select statement
// the process exits. This can be used in cases such a select statement
// waiting on the process to end.
// waiting on the process to end.
func
(
r
*
RemoteCommand
)
ExitChan
()
(
<-
chan
int
)
{
func
(
r
*
RemoteCommand
)
ExitChan
()
<-
chan
int
{
// TODO(mitchellh): Something more efficient than multiple Wait() calls
r
.
exitChanLock
.
Lock
()
r
.
exitChanLock
.
Lock
()
defer
r
.
exitChanLock
.
Unlock
()
defer
r
.
exitChanLock
.
Unlock
()
// Make a single buffered channel so that the send doesn't block.
// If we haven't made any channels yet, make that slice
exitChan
:=
make
(
chan
int
,
1
)
if
r
.
exitChans
==
nil
{
r
.
exitChans
=
make
([]
chan
<-
int
,
0
,
5
)
go
func
()
{
go
func
()
{
defer
close
(
exitChan
)
// Wait for the command to finish
r
.
Wait
()
r
.
Wait
()
exitChan
<-
r
.
ExitStatus
// Grab the exit chan lock so we can iterate over it and
// message to each channel.
r
.
exitChanLock
.
Lock
()
defer
r
.
exitChanLock
.
Unlock
()
for
_
,
ch
:=
range
r
.
exitChans
{
// Use a select so the send never blocks
select
{
case
ch
<-
r
.
ExitStatus
:
default
:
log
.
Println
(
"remote command exit channel wouldn't blocked. Weird."
)
}
close
(
ch
)
}
r
.
exitChans
=
nil
}()
}()
}
// Append our new channel onto it and return it
exitChan
:=
make
(
chan
int
,
1
)
r
.
exitChans
=
append
(
r
.
exitChans
,
exitChan
)
return
exitChan
return
exitChan
}
}
...
...
packer/rpc/communicator.go
View file @
ace53450
packer/rpc/communicator_test.go
View file @
ace53450
packer/rpc/ui_test.go
View file @
ace53450
plugin/provisioner-shell/main.go
View file @
ace53450
package
main
package
main
import
(
import
(
"github.com/mitchellh/packer/provisioner/shell"
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/provisioner/shell"
)
)
func
main
()
{
func
main
()
{
...
...
provisioner/shell/provisioner_test.go
View file @
ace53450
...
@@ -14,7 +14,7 @@ func TestProvisioner_Impl(t *testing.T) {
...
@@ -14,7 +14,7 @@ func TestProvisioner_Impl(t *testing.T) {
}
}
func
TestProvisionerPrepare_Defaults
(
t
*
testing
.
T
)
{
func
TestProvisionerPrepare_Defaults
(
t
*
testing
.
T
)
{
raw
:=
map
[
string
]
interface
{}
{}
raw
:=
map
[
string
]
interface
{}{}
p
:=
&
Provisioner
{}
p
:=
&
Provisioner
{}
p
.
Prepare
(
raw
,
nil
)
p
.
Prepare
(
raw
,
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment