Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data race #162

Merged
merged 1 commit into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,34 @@ func ExecCommand(app *kingpin.Application, input ExecCommandInput) {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Start(); err != nil {
app.Errorf("%v", err)
return
}
// wait for the command to finish
waitCh := make(chan error, 1)
go func() {
sig := <-input.Signals
if cmd.Process != nil {
cmd.Process.Signal(sig)
}
waitCh <- cmd.Wait()
close(waitCh)
}()

var waitStatus syscall.WaitStatus
if err := cmd.Run(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus = exitError.Sys().(syscall.WaitStatus)
os.Exit(waitStatus.ExitStatus())
}
if err != nil {
app.Errorf("%v", err)
for {
select {
case sig := <-input.Signals:
if err = cmd.Process.Signal(sig); err != nil {
app.Errorf("%v", err)
break
}
case err := <-waitCh:
var waitStatus syscall.WaitStatus
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus = exitError.Sys().(syscall.WaitStatus)
os.Exit(waitStatus.ExitStatus())
}
if err != nil {
app.Errorf("%v", err)
return
}
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ExampleExecCommand() {
{Key: "llamas", Data: []byte(`{"AccessKeyID":"ABC","SecretAccessKey":"XYZ"}`)},
})

app := kingpin.New(`aws-vault`, ``)
app := kingpin.New("aws-vault", "")
ConfigureGlobals(app)
ConfigureExecCommand(app)
kingpin.MustParse(app.Parse([]string{
Expand Down