diff options
| author | Tobias Klauser <tklauser@distanz.ch> | 2020-06-29 10:33:34 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-06-29 13:34:06 +0200 |
| commit | df01f6fc27049d8d791f09e6bd04ab9dc5074a7c (patch) | |
| tree | d44ba119f6558d794968998acbbcea5a5a6d2ecd /pkg/osutil | |
| parent | 344d949f1e872b3d433c8586902b5ea36eab3a32 (diff) | |
pkg/osutil: use functionality from x/sys/unix
Use unix.Unmount instead of manually wrapping SYS_UMOUNT2.
Use unix.IoctlSetPointerInt instead of manually wrapping SYS_IOCTL. This
also allows to use FS_IOC_SETFLAGS instead of manually defining it for
each GOARCH.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'pkg/osutil')
| -rw-r--r-- | pkg/osutil/osutil_linux.go | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go index e0b67a88f..7ed109662 100644 --- a/pkg/osutil/osutil_linux.go +++ b/pkg/osutil/osutil_linux.go @@ -11,13 +11,13 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strconv" "strings" "sync" "syscall" "time" - "unsafe" + + "golang.org/x/sys/unix" ) // RemoveAll is similar to os.RemoveAll, but can handle more cases. @@ -28,8 +28,7 @@ func RemoveAll(dir string) error { if f.IsDir() { RemoveAll(name) } - fn := []byte(name + "\x00") - syscall.Syscall(syscall.SYS_UMOUNT2, uintptr(unsafe.Pointer(&fn[0])), syscall.MNT_FORCE, 0) + unix.Unmount(name, unix.MNT_FORCE) } if err := os.RemoveAll(dir); err != nil { removeImmutable(dir) @@ -51,20 +50,7 @@ func removeImmutable(fname string) error { return err } defer syscall.Close(fd) - flags := 0 - var cmd uint64 // FS_IOC_SETFLAGS - switch runtime.GOARCH { - case "386", "arm": - cmd = 1074030082 - case "amd64", "arm64", "riscv64", "s390x": - cmd = 1074292226 - case "ppc64le", "mips64le": - cmd = 2148034050 - default: - panic("unknown arch") - } - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(&flags))) - return errno + return unix.IoctlSetPointerInt(fd, unix.FS_IOC_SETFLAGS, 0) } func Sandbox(cmd *exec.Cmd, user, net bool) error { |
