diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2020-10-14 14:31:38 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2020-10-16 14:17:44 -0300 |
commit | cb49c65bb5581b5ca6122898716aad1f075982d8 (patch) | |
tree | cb7a33adffca63e59802ba2a8104f6155929d6f0 /sysdeps/unix/sysv/linux/fstatat.c | |
parent | 9030377480effce89f382499ff47a22467112436 (diff) | |
download | glibc-cb49c65bb5581b5ca6122898716aad1f075982d8.tar.gz |
linux: Use INTERNAL_SYSCALL on fstatat{64}
Although not required by the standards, some code expects that a
successful stat call should not set errno. However since aa03f722f3b99
'linux: Add {f}stat{at} y2038 support', on 32-bit systems with 32-bit
time_t supporrt, stat implementation will first issues __NR_statx and
if it fails with ENOSYS issue the system stat syscall.
On architecture running on kernel without __NR_statx support the
first call will set the errno to ENOSYS, even when the following stat
syscall might not fail.
This patch fixes by using INTERNAL_SYSCALL and only setting the errno
value when function returns.
Checked on i686-linux-gnu, x86_64-linux-gnu, sparc64-linux-gnu,
sparcv9-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu,
arm-linux-gnueabihf, and aarch64-linux-gnu.
Diffstat (limited to 'sysdeps/unix/sysv/linux/fstatat.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/fstatat.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c index c7fcfaf277..db49e3155c 100644 --- a/sysdeps/unix/sysv/linux/fstatat.c +++ b/sysdeps/unix/sysv/linux/fstatat.c @@ -26,21 +26,22 @@ int __fstatat (int fd, const char *file, struct stat *buf, int flag) { + int r; + # if STAT_IS_KERNEL_STAT /* New kABIs which uses generic pre 64-bit time Linux ABI, e.g. csky, nios2 */ - int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, buf, flag); + r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, buf, flag); if (r == 0 && (buf->__st_ino_pad != 0 || buf->__st_size_pad != 0 || buf->__st_blocks_pad != 0)) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); - return r; # else # ifdef __NR_fstatat64 /* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32, microblaze, s390, sh, powerpc, and sparc. */ struct stat64 st64; - int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); + r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); if (r == 0) { if (! in_ino_t_range (st64.st_ino) @@ -67,15 +68,21 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag) buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec; buf->st_ctim.tv_sec = st64.st_ctim.tv_sec; buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec; + + return 0; } - return r; # else /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */ struct kernel_stat kst; - int r = INLINE_SYSCALL_CALL (newfstatat, fd, file, &kst, flag); - return r ?: __cp_kstat_stat (&kst, buf); + r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag); + if (r == 0) + r = __cp_kstat_stat (&kst, buf); # endif /* __nr_fstatat64 */ # endif /* STAT_IS_KERNEL_STAT */ + + return INTERNAL_SYSCALL_ERROR_P (r) + ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r) + : 0; } weak_alias (__fstatat, fstatat) |