aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/image/fsck.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/image/fsck.go')
-rw-r--r--pkg/image/fsck.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/image/fsck.go b/pkg/image/fsck.go
index e749871f9..fbaeca9c4 100644
--- a/pkg/image/fsck.go
+++ b/pkg/image/fsck.go
@@ -11,7 +11,9 @@ import (
"os/exec"
"strconv"
"strings"
+ "sync"
+ "github.com/google/syzkaller/pkg/log"
"github.com/google/syzkaller/pkg/osutil"
)
@@ -59,3 +61,27 @@ func Fsck(r io.Reader, fsckCmd string) ([]byte, bool, error) {
prefix := fsckCmd + " exited with status code " + strconv.Itoa(exitCode) + "\n"
return append([]byte(prefix), output...), exitCode == 0, nil
}
+
+type FsckChecker struct {
+ mu sync.Mutex
+ exists map[string]bool
+}
+
+func (fc *FsckChecker) Exists(cmd string) bool {
+ fc.mu.Lock()
+ defer fc.mu.Unlock()
+ bin := strings.Fields(cmd)[0]
+ if ret, ok := fc.exists[bin]; ok {
+ return ret
+ }
+ if fc.exists == nil {
+ fc.exists = map[string]bool{}
+ }
+ _, err := exec.LookPath(bin)
+ found := err == nil
+ if !found {
+ log.Logf(0, "%s not found, images won't be checked", bin)
+ }
+ fc.exists[bin] = found
+ return found
+}