diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2019-02-08 16:18:19 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-02-08 16:27:53 +0100 |
| commit | 381ccbf2f8752e9369efc68aacae65f769378ba3 (patch) | |
| tree | dd38816c52a0c7ebcf473737f7a1c1a1aaa297ae /pkg/osutil | |
| parent | 78a290863d6375b7c568b6fb2b8e34663d42a78a (diff) | |
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.
Diffstat (limited to 'pkg/osutil')
| -rw-r--r-- | pkg/osutil/osutil_linux.go | 30 |
1 files changed, 29 insertions, 1 deletions
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 { |
