pkg/kernel: fix CreateImage

- Move does not work across filesystems (i.e. tmpfs->disk)
- set proper permissions for ssh key
This commit is contained in:
Dmitry Vyukov 2017-06-19 16:47:42 +02:00
parent 4799d21e01
commit 9dcb6799c7

View File

@ -21,6 +21,7 @@ import (
"strings"
"time"
"github.com/google/syzkaller/pkg/fileutil"
"github.com/google/syzkaller/pkg/osutil"
)
@ -75,10 +76,13 @@ func CreateImage(kernelDir, userspaceDir, image, sshkey string) error {
if _, err := osutil.RunCmd(time.Hour, tempDir, scriptFile, userspaceDir, bzImage); err != nil {
return fmt.Errorf("image build failed: %v", err)
}
if err := os.Rename(filepath.Join(tempDir, "disk.raw"), image); err != nil {
if err := fileutil.CopyFile(filepath.Join(tempDir, "disk.raw"), image); err != nil {
return err
}
if err := os.Rename(filepath.Join(tempDir, "key"), sshkey); err != nil {
if err := fileutil.CopyFile(filepath.Join(tempDir, "key"), sshkey); err != nil {
return err
}
if err := os.Chmod(sshkey, 0600); err != nil {
return err
}
return nil