1
0
mirror of https://github.com/moby/moby.git synced 2025-12-10 21:42:47 +03:00

integcli: add & use dockerCmdWithTimeout & InDir

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack
2014-08-13 19:02:04 +03:00
parent 5d1cb9d005
commit c6965e3e45
3 changed files with 54 additions and 43 deletions

View File

@@ -63,6 +63,31 @@ func runCommandWithStdoutStderr(cmd *exec.Cmd) (stdout string, stderr string, ex
return
}
var ErrCmdTimeout = fmt.Errorf("command timed out")
func runCommandWithOutputAndTimeout(cmd *exec.Cmd, timeout time.Duration) (output string, exitCode int, err error) {
done := make(chan error)
go func() {
output, exitCode, err = runCommandWithOutput(cmd)
if err != nil || exitCode != 0 {
done <- fmt.Errorf("failed to run command: %s", err)
return
}
done <- nil
}()
select {
case <-time.After(timeout):
killFailed := cmd.Process.Kill()
if killFailed == nil {
fmt.Printf("failed to kill (pid=%d): %v\n", cmd.Process.Pid, err)
}
err = ErrCmdTimeout
case <-done:
break
}
return
}
func runCommand(cmd *exec.Cmd) (exitCode int, err error) {
exitCode = 0
err = cmd.Run()