mirror of
https://github.com/hanzoai/go-fuse.git
synced 2026-10-30 14:46:18 +00:00
This change is necessary for kernels that don't support openat2. Change-Id: I8f2c0f6cca4599a3139eba98877a2354cdb1d140
21 lines
557 B
Go
21 lines
557 B
Go
package openat
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func openatNoSymlinks(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
|
|
how := unix.OpenHow{
|
|
// os/exec expects all fds to have O_CLOEXEC or it will leak them to subprocesses.
|
|
Flags: uint64(flags) | unix.O_CLOEXEC,
|
|
Mode: uint64(mode),
|
|
Resolve: unix.RESOLVE_NO_SYMLINKS,
|
|
}
|
|
fd, err = unix.Openat2(dirfd, path, &how)
|
|
if err != nil && err == unix.ENOSYS {
|
|
flags |= unix.O_NOFOLLOW | unix.O_CLOEXEC
|
|
fd, err = unix.Openat(dirfd, path, flags, mode)
|
|
}
|
|
return fd, err
|
|
}
|