aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-12-07 00:05:28 +0100
committerJakob Unterwurzacher2017-12-07 00:05:28 +0100
commit2ceef01afecafbd4aa80276869993cb53bdadcf4 (patch)
tree79766712b8f5f022f833b50e1f616eef18e8d01e /internal
parent6bd2da89d3753a589a927517771922a0db76bb36 (diff)
syscallcompat: add Faccessat
Add faccessat(2) with a hack for symlink, because the kernel does not actually looks at the passed flags. From man 2 faccessat: C library/kernel differences The raw faccessat() system call takes only the first three argu‐ ments. The AT_EACCESS and AT_SYMLINK_NOFOLLOW flags are actually implemented within the glibc wrapper function for faccessat().
Diffstat (limited to 'internal')
-rw-r--r--internal/syscallcompat/sys_common.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go
index 440b42f..896aaf7 100644
--- a/internal/syscallcompat/sys_common.go
+++ b/internal/syscallcompat/sys_common.go
@@ -1,6 +1,8 @@
package syscallcompat
import (
+ "syscall"
+
"golang.org/x/sys/unix"
)
@@ -21,3 +23,18 @@ func Readlinkat(dirfd int, path string) (string, error) {
}
}
}
+
+// Faccessat exists both in Linux and in MacOS 10.10+, but the Linux version
+// DOES NOT support any flags. Emulate AT_SYMLINK_NOFOLLOW like glibc does.
+func Faccessat(dirfd int, path string, mode uint32) error {
+ var st unix.Stat_t
+ err := Fstatat(dirfd, path, &st, unix.AT_SYMLINK_NOFOLLOW)
+ if err != nil {
+ return err
+ }
+ if st.Mode&syscall.S_IFMT == syscall.S_IFLNK {
+ // Pretend that a symlink is always accessible
+ return nil
+ }
+ return unix.Faccessat(dirfd, path, mode, 0)
+}