diff --git a/util/binfmt_misc/check.go b/util/binfmt_misc/check.go deleted file mode 100644 index 4caf5944..00000000 --- a/util/binfmt_misc/check.go +++ /dev/null @@ -1,42 +0,0 @@ -package binfmt_misc - -import ( - "bytes" - "compress/gzip" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" -) - -func check(bin string) error { - tmpdir, err := ioutil.TempDir("", "qemu-check") - if err != nil { - return err - } - defer os.RemoveAll(tmpdir) - pp := filepath.Join(tmpdir, "check") - - r, err := gzip.NewReader(bytes.NewReader([]byte(bin))) - if err != nil { - return err - } - defer r.Close() - - f, err := os.OpenFile(pp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700) - if err != nil { - return err - } - - if _, err := io.Copy(f, r); err != nil { - f.Close() - return err - } - f.Close() - - cmd := exec.Command("/check") - withChroot(cmd, tmpdir) - err = cmd.Run() - return err -} diff --git a/util/binfmt_misc/check_unix.go b/util/binfmt_misc/check_unix.go index 22c7ce7c..670e6d2c 100644 --- a/util/binfmt_misc/check_unix.go +++ b/util/binfmt_misc/check_unix.go @@ -3,7 +3,13 @@ package binfmt_misc import ( + "bytes" + "compress/gzip" + "io" + "io/ioutil" + "os" "os/exec" + "path/filepath" "syscall" ) @@ -12,3 +18,34 @@ func withChroot(cmd *exec.Cmd, dir string) { Chroot: dir, } } + +func check(bin string) error { + tmpdir, err := ioutil.TempDir("", "qemu-check") + if err != nil { + return err + } + defer os.RemoveAll(tmpdir) + pp := filepath.Join(tmpdir, "check") + + r, err := gzip.NewReader(bytes.NewReader([]byte(bin))) + if err != nil { + return err + } + defer r.Close() + + f, err := os.OpenFile(pp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700) + if err != nil { + return err + } + + if _, err := io.Copy(f, r); err != nil { + f.Close() + return err + } + f.Close() + + cmd := exec.Command("/check") + withChroot(cmd, tmpdir) + err = cmd.Run() + return err +} diff --git a/util/binfmt_misc/check_windows.go b/util/binfmt_misc/check_windows.go index 3c28c8bd..f2461847 100644 --- a/util/binfmt_misc/check_windows.go +++ b/util/binfmt_misc/check_windows.go @@ -3,8 +3,13 @@ package binfmt_misc import ( + "errors" "os/exec" ) func withChroot(cmd *exec.Cmd, dir string) { } + +func check(bin string) error { + return errors.New("binfmt is not supported on Windows") +}