]> sourceware.org Git - glibc.git/commitdiff
Linux: Use faccessat2 to implement faccessat (bug 18683)
authorFlorian Weimer <fweimer@redhat.com>
Fri, 7 Aug 2020 20:06:59 +0000 (22:06 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 7 Aug 2020 20:06:59 +0000 (22:06 +0200)
This provides correct AT_EACCESS handling and also takes
Linux security modules into account.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
sysdeps/unix/sysv/linux/faccessat.c
sysdeps/unix/sysv/linux/kernel-features.h

index e4f18ab2db1b90b47ace49c05b92fbad4a9376b4..56cb6dcc8b4d58d30100590d56b817fd6974f8df 100644 (file)
 int
 faccessat (int fd, const char *file, int mode, int flag)
 {
+  int ret = INLINE_SYSCALL_CALL (faccessat2, fd, file, mode, flag);
+#if __ASSUME_FACCESSAT2
+  return ret;
+#else
+  if (ret == 0 || errno != ENOSYS)
+    return ret;
+
   if (flag & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS))
     return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
 
@@ -41,9 +48,9 @@ faccessat (int fd, const char *file, int mode, int flag)
     return -1;
 
   mode &= (X_OK | W_OK | R_OK);        /* Clear any bogus bits. */
-#if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
-# error Oops, portability assumptions incorrect.
-#endif
+# if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
+#  error Oops, portability assumptions incorrect.
+# endif
 
   if (mode == F_OK)
     return 0;                  /* The file exists. */
@@ -68,4 +75,5 @@ faccessat (int fd, const char *file, int mode, int flag)
     return 0;
 
   return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES);
+#endif /* !__ASSUME_FACCESSAT2 */
 }
index 32533e94cf6febc396bf9fdcae6f00084c915049..a6bbc3c94e8b4360690741cc9079d47bfa5b248e 100644 (file)
 # define __ASSUME_WAITID_PID0_P_PGID
 #endif
 
+/* The faccessat2 system call was introduced across all architectures
+   in Linux 5.8.  */
+#if __LINUX_KERNEL_VERSION >= 0x050800
+# define __ASSUME_FACCESSAT2 1
+#else
+# define __ASSUME_FACCESSAT2 0
+#endif
+
 #endif /* kernel-features.h */
This page took 0.047914 seconds and 5 git commands to generate.