From df01f6fc27049d8d791f09e6bd04ab9dc5074a7c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 29 Jun 2020 10:33:34 +0200 Subject: 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 --- pkg/osutil/osutil_linux.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'pkg/osutil/osutil_linux.go') 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 { -- cgit mrf-deployment