From 381ccbf2f8752e9369efc68aacae65f769378ba3 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 8 Feb 2019 16:18:19 +0100 Subject: pkg/ipc: generate better temp name for executor Just appending the pid number can produce conflicting names if the name itself ends with digits (standard temp file naming convention). So append ".PID". Also remove beginning from too long names instead of ending. Temp files in tests has unique numbers at the end, we need to preserve them to avoid file name conflicts. --- pkg/osutil/osutil_linux.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'pkg/osutil') diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go index f4b30b195..1ec37d45f 100644 --- a/pkg/osutil/osutil_linux.go +++ b/pkg/osutil/osutil_linux.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strconv" "strings" "sync" @@ -30,7 +31,34 @@ func RemoveAll(dir string) error { fn := []byte(name + "\x00") syscall.Syscall(syscall.SYS_UMOUNT2, uintptr(unsafe.Pointer(&fn[0])), syscall.MNT_FORCE, 0) } - return os.RemoveAll(dir) + if err := os.RemoveAll(dir); err != nil { + removeImmutable(dir) + return os.RemoveAll(dir) + } + return nil +} + +func removeImmutable(fname string) error { + // Reset FS_XFLAG_IMMUTABLE/FS_XFLAG_APPEND. + fd, err := syscall.Open(fname, syscall.O_RDONLY, 0) + if err != nil { + 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": + cmd = 1074292226 + case "ppc64le": + cmd = 2148034050 + default: + panic("unknown arch") + } + _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(&flags))) + return errno } func Sandbox(cmd *exec.Cmd, user, net bool) error { -- cgit mrf-deployment