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
6f742cb3
Commit
6f742cb3
authored
Aug 21, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: fix data race in communicator
parent
c71419f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
packer/communicator.go
packer/communicator.go
+11
-6
packer/communicator_test.go
packer/communicator_test.go
+3
-0
No files found.
packer/communicator.go
View file @
6f742cb3
...
...
@@ -33,9 +33,11 @@ type RemoteCmd struct {
// Once Exited is true, this will contain the exit code of the process.
ExitStatus
int
// Internal locks and such used for safely setting some shared variables
l
sync
.
Mutex
// Internal fields
exitCh
chan
struct
{}
// This thing is a mutex, lock when making modifications concurrently
sync
.
Mutex
}
// A Communicator is the interface used to communicate with the machine
...
...
@@ -76,6 +78,9 @@ func (r *RemoteCmd) StartWithUi(c Communicator, ui Ui) error {
originalStdout
:=
r
.
Stdout
originalStderr
:=
r
.
Stderr
defer
func
()
{
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Stdout
=
originalStdout
r
.
Stderr
=
originalStderr
}()
...
...
@@ -141,8 +146,8 @@ OutputLoop:
// should be called by communicators who are running a remote command in
// order to set that the command is done.
func
(
r
*
RemoteCmd
)
SetExited
(
status
int
)
{
r
.
l
.
Lock
()
defer
r
.
l
.
Unlock
()
r
.
Lock
()
defer
r
.
Unlock
()
if
r
.
exitCh
==
nil
{
r
.
exitCh
=
make
(
chan
struct
{})
...
...
@@ -156,11 +161,11 @@ func (r *RemoteCmd) SetExited(status int) {
// Wait waits for the remote command to complete.
func
(
r
*
RemoteCmd
)
Wait
()
{
// Make sure our condition variable is initialized.
r
.
l
.
Lock
()
r
.
Lock
()
if
r
.
exitCh
==
nil
{
r
.
exitCh
=
make
(
chan
struct
{})
}
r
.
l
.
Unlock
()
r
.
Unlock
()
<-
r
.
exitCh
}
...
...
packer/communicator_test.go
View file @
6f742cb3
...
...
@@ -15,6 +15,9 @@ type TestCommunicator struct {
func
(
c
*
TestCommunicator
)
Start
(
rc
*
RemoteCmd
)
error
{
go
func
()
{
rc
.
Lock
()
defer
rc
.
Unlock
()
if
rc
.
Stdout
!=
nil
&&
c
.
Stdout
!=
nil
{
io
.
Copy
(
rc
.
Stdout
,
c
.
Stdout
)
}
...
...
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