some bug fixes

This commit is contained in:
ston1th 2019-05-05 19:06:51 +02:00
commit 0e914c629e
16 changed files with 179 additions and 52 deletions

39
pkg/scan/timeout.go Normal file
View file

@ -0,0 +1,39 @@
// Copyright (C) 2019 Marius Schellenberger
package scan
import (
"fmt"
"os/exec"
"time"
)
func timeout(cmd *exec.Cmd, t time.Duration) (output []byte, err error) {
done := make(chan error)
out := make(chan []byte)
go func() {
o, e := cmd.Output()
done <- e
out <- o
}()
select {
case <-time.After(t):
e := cmd.Process.Kill()
err = <-done
<-out
if e != nil {
err = e
} else {
err = fmt.Errorf("command '%s' timed out: %s", cmd.Path, err)
}
case e := <-done:
exerr, ok := e.(*exec.ExitError)
if ok {
err = fmt.Errorf("%s\n%s", e, string(exerr.Stderr))
} else {
err = e
}
output = <-out
}
return
}