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
23450837
Commit
23450837
authored
Jul 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctrl-c closes stdin for plugins so that they are unblocked
parent
35ee6313
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletion
+41
-1
packer.go
packer.go
+3
-0
signal.go
signal.go
+1
-1
stdin.go
stdin.go
+37
-0
No files found.
packer.go
View file @
23450837
...
...
@@ -46,6 +46,9 @@ func main() {
packer
.
Version
,
packer
.
VersionPrerelease
,
packer
.
GitCommit
)
log
.
Printf
(
"Packer Target OS/Arch: %s %s"
,
runtime
.
GOOS
,
runtime
.
GOARCH
)
// Prepare stdin for plugin usage by switching it to a pipe
setupStdin
()
config
,
err
:=
loadConfig
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error loading configuration:
\n\n
%s
\n
"
,
err
)
...
...
signal.go
View file @
23450837
...
...
@@ -18,7 +18,7 @@ func setupSignalHandlers(env packer.Environment) {
// First interrupt. We mostly ignore this because it allows the
// plugins time to cleanup.
<-
ch
log
.
Println
(
"First interrupt. Ignoring
, but closing stdin..
."
)
log
.
Println
(
"First interrupt. Ignoring
to allow plugins to clean up
."
)
// Second interrupt. Go down hard.
<-
ch
...
...
stdin.go
0 → 100644
View file @
23450837
package
main
import
(
"io"
"log"
"os"
"os/signal"
)
// setupStdin switches out stdin for a pipe. We do this so that we can
// close the writer end of the pipe when we receive an interrupt so plugins
// blocked on reading from stdin are unblocked.
func
setupStdin
()
{
// Create the pipe and swap stdin for the reader end
r
,
w
,
_
:=
os
.
Pipe
()
originalStdin
:=
os
.
Stdin
os
.
Stdin
=
r
// Create a goroutine that copies data from the original stdin
// into the writer end of the pipe forever.
go
func
()
{
defer
w
.
Close
()
io
.
Copy
(
w
,
originalStdin
)
}()
// Register a signal handler for interrupt in order to close the
// writer end of our pipe so that readers get EOF downstream.
ch
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
ch
,
os
.
Interrupt
)
go
func
()
{
defer
signal
.
Stop
(
ch
)
defer
w
.
Close
()
<-
ch
log
.
Println
(
"Closing stdin because interrupt received."
)
}()
}
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