Skip to content

Commit

Permalink
Get the exit status from the wrapped command and exit etcdenv with th…
Browse files Browse the repository at this point in the history
…is code
  • Loading branch information
AlexisMontagne committed Apr 26, 2015
1 parent 3c423c1 commit 9b6df65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions etcdenv/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"github.com/cenkalti/backoff"
"github.com/coreos/go-etcd/etcd"
"log"
"os"
"os/exec"
"reflect"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -172,20 +175,29 @@ func (ctx *Context) Run() {
}

} else {
processExitChan := make(chan bool)
processExitChan := make(chan int)

time.Sleep(200 * time.Millisecond)

go func() {
ctx.Runner.Wait()
processExitChan <- true
err := ctx.Runner.Wait()
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
processExitChan <- status.ExitStatus()
} else {
processExitChan <- 0
}
} else {
processExitChan <- 0
}
}()

select {
case <-ctx.ExitChan:
ctx.Runner.Stop()
case <-processExitChan:
case status := <-processExitChan:
ctx.ExitChan <- true
os.Exit(status)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions etcdenv/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (r *Runner) Start(envVariables map[string]string) error {
r.cmd.Stderr = os.Stderr
r.cmd.Stdin = os.Stdin

go r.cmd.Run()
r.cmd.Start()

return nil
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func (r *Runner) Wait() error {
return newError(ErrNotStarted)
}

_, err := r.cmd.Process.Wait()
err := r.cmd.Wait()

return err
}

0 comments on commit 9b6df65

Please sign in to comment.