diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-07-03 14:00:47 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-07-03 14:00:47 +0200 |
| commit | a7b199253f7a517fd62f36a5d632efee3bac737e (patch) | |
| tree | 9f981ff2814ed7389e973c02376f8b2618224be2 /vm | |
| parent | 1438a6de8130467a2fcde187ba80b8a616f8daa0 (diff) | |
all: use consistent file permissions
Currently we have unix permissions for new files/dirs
hardcoded throughout the code base. Some places use 0644,
some - 0640, some - 0600 and a variety of other constants.
Introduce osutil.MkdirAll/WriteFile that use the default
permissions and use them throughout the code base.
This makes permissions consistent and also allows to easily
change the permissions later if we change our minds.
Also merge pkg/fileutil into pkg/osutil as they become
dependent on each other. The line between them was poorly
defined anyway as both operate on files.
Diffstat (limited to 'vm')
| -rw-r--r-- | vm/kvm/kvm.go | 8 | ||||
| -rw-r--r-- | vm/qemu/qemu.go | 3 | ||||
| -rw-r--r-- | vm/vm.go | 4 |
3 files changed, 6 insertions, 9 deletions
diff --git a/vm/kvm/kvm.go b/vm/kvm/kvm.go index 8f17f260c..c404ba917 100644 --- a/vm/kvm/kvm.go +++ b/vm/kvm/kvm.go @@ -7,7 +7,6 @@ package kvm import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -17,7 +16,6 @@ import ( "time" "github.com/google/syzkaller/pkg/config" - "github.com/google/syzkaller/pkg/fileutil" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/vm/vmimpl" ) @@ -121,7 +119,7 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { return nil, fmt.Errorf("failed to lkvm setup: %v\n%s", err, out) } scriptPath := filepath.Join(workdir, "script.sh") - if err := ioutil.WriteFile(scriptPath, []byte(script), 0700); err != nil { + if err := osutil.WriteExecFile(scriptPath, []byte(script)); err != nil { return nil, fmt.Errorf("failed to create temp file: %v", err) } @@ -218,7 +216,7 @@ func (inst *instance) Forward(port int) (string, error) { func (inst *instance) Copy(hostSrc string) (string, error) { vmDst := filepath.Join("/", filepath.Base(hostSrc)) dst := filepath.Join(inst.sandboxPath, vmDst) - if err := fileutil.CopyFile(hostSrc, dst); err != nil { + if err := osutil.CopyFile(hostSrc, dst); err != nil { return "", err } if err := os.Chmod(dst, 0777); err != nil { @@ -237,7 +235,7 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin cmdFile := filepath.Join(inst.sandboxPath, "/syz-cmd") tmpFile := cmdFile + "-tmp" - if err := ioutil.WriteFile(tmpFile, []byte(command), 0700); err != nil { + if err := osutil.WriteExecFile(tmpFile, []byte(command)); err != nil { return nil, nil, err } if err := os.Rename(tmpFile, cmdFile); err != nil { diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go index a264d00b1..dc6c0158e 100644 --- a/vm/qemu/qemu.go +++ b/vm/qemu/qemu.go @@ -6,7 +6,6 @@ package qemu import ( "fmt" "io" - "io/ioutil" "math/rand" "net" "os" @@ -117,7 +116,7 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { return nil, fmt.Errorf("failed to execute ssh-keygen: %v\n%s", err, out) } initFile := filepath.Join(workdir, "init.sh") - if err := ioutil.WriteFile(initFile, []byte(strings.Replace(initScript, "{{KEY}}", sshkey, -1)), 0777); err != nil { + if err := osutil.WriteExecFile(initFile, []byte(strings.Replace(initScript, "{{KEY}}", sshkey, -1))); err != nil { return nil, fmt.Errorf("failed to create init file: %v", err) } } @@ -15,7 +15,7 @@ import ( "regexp" "time" - "github.com/google/syzkaller/pkg/fileutil" + "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" "github.com/google/syzkaller/vm/vmimpl" @@ -63,7 +63,7 @@ func (pool *Pool) Create(index int) (*Instance, error) { if index < 0 || index >= pool.Count() { return nil, fmt.Errorf("invalid VM index %v (count %v)", index, pool.Count()) } - workdir, err := fileutil.ProcessTempDir(pool.workdir) + workdir, err := osutil.ProcessTempDir(pool.workdir) if err != nil { return nil, fmt.Errorf("failed to create instance temp dir: %v", err) } |
