diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-06-21 17:58:12 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-06-22 16:40:45 +0200 |
| commit | c97f0d7a863bbb63de5dca44ad75c5ae7b4a154d (patch) | |
| tree | 75f9f638714eaab50b73250bdceadd860e48556b /pkg | |
| parent | 91f52697d10d451839cd60ffcd6323e99af14011 (diff) | |
pkg/build: add gvisor support
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/gvisor.go | 19 | ||||
| -rw-r--r-- | pkg/osutil/osutil.go | 21 |
2 files changed, 34 insertions, 6 deletions
diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go index 8649e7e65..b96d55cf0 100644 --- a/pkg/build/gvisor.go +++ b/pkg/build/gvisor.go @@ -3,13 +3,32 @@ package build +import ( + "path/filepath" + "time" + + "github.com/google/syzkaller/pkg/osutil" +) + type gvisor struct{} func (gvisor) build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir, cmdlineFile, sysctlFile string, config []byte) error { + if err := osutil.MkdirAll(outputDir); err != nil { + return err + } + if _, err := osutil.RunCmd(20*time.Minute, kernelDir, compiler, "build", "--verbose_failures", "--sandbox_debug", "runsc"); err != nil { + return err + } + runsc := filepath.Join(kernelDir, "bazel-bin", "runsc", "linux_amd64_pure_stripped", "runsc") + if err := osutil.CopyFile(runsc, filepath.Join(outputDir, "image")); err != nil { + return err + } + osutil.RunCmd(10*time.Minute, kernelDir, compiler, "shutdown") return nil } func (gvisor) clean(kernelDir string) error { + // Let's assume that bazel always properly handles build without cleaning (until proven otherwise). return nil } diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index e41ad7ec1..42b65d36a 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -89,8 +89,11 @@ func IsExist(name string) bool { // FilesExist returns true if all files exist in dir. // Files are assumed to be relative names in slash notation. -func FilesExist(dir string, files []string) bool { - for _, f := range files { +func FilesExist(dir string, files map[string]bool) bool { + for f, required := range files { + if !required { + continue + } if !IsExist(filepath.Join(dir, filepath.FromSlash(f))) { return false } @@ -101,7 +104,7 @@ func FilesExist(dir string, files []string) bool { // CopyFiles copies files from srcDir to dstDir as atomically as possible. // Files are assumed to be relative names in slash notation. // All other files in dstDir are removed. -func CopyFiles(srcDir, dstDir string, files []string) error { +func CopyFiles(srcDir, dstDir string, files map[string]bool) error { // Linux does not support atomic dir replace, so we copy to tmp dir first. // Then remove dst dir and rename tmp to dst (as atomic as can get on Linux). tmpDir := dstDir + ".tmp" @@ -111,8 +114,11 @@ func CopyFiles(srcDir, dstDir string, files []string) error { if err := MkdirAll(tmpDir); err != nil { return err } - for _, f := range files { + for f, required := range files { src := filepath.Join(srcDir, filepath.FromSlash(f)) + if !required && !IsExist(src) { + continue + } dst := filepath.Join(tmpDir, filepath.FromSlash(f)) if err := MkdirAll(filepath.Dir(dst)); err != nil { return err @@ -130,15 +136,18 @@ func CopyFiles(srcDir, dstDir string, files []string) error { // LinkFiles creates hard links for files from dstDir to srcDir. // Files are assumed to be relative names in slash notation. // All other files in dstDir are removed. -func LinkFiles(srcDir, dstDir string, files []string) error { +func LinkFiles(srcDir, dstDir string, files map[string]bool) error { if err := os.RemoveAll(dstDir); err != nil { return err } if err := MkdirAll(dstDir); err != nil { return err } - for _, f := range files { + for f, required := range files { src := filepath.Join(srcDir, filepath.FromSlash(f)) + if !required && !IsExist(src) { + continue + } dst := filepath.Join(dstDir, filepath.FromSlash(f)) if err := MkdirAll(filepath.Dir(dst)); err != nil { return err |
