mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
Add renameat2 function [BZ #17662]
The implementation falls back to renameat if renameat2 is not available in the kernel (or in the kernel headers) and the flags argument is zero. Without kernel support, a non-zero argument returns EINVAL, not ENOSYS. This mirrors what the kernel does for invalid renameat2 flags.
This commit is contained in:
@ -2132,3 +2132,4 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
|
@ -35,6 +35,11 @@
|
||||
#define __ASSUME_RECV_SYSCALL 1
|
||||
#define __ASSUME_SEND_SYSCALL 1
|
||||
|
||||
/* Support for the renameat2 syscall was added in 3.17. */
|
||||
#if __LINUX_KERNEL_VERSION < 0x031100
|
||||
# undef __ASSUME_RENAMEAT2
|
||||
#endif
|
||||
|
||||
/* Support for the execveat syscall was added in 4.2. */
|
||||
#if __LINUX_KERNEL_VERSION < 0x040200
|
||||
# undef __ASSUME_EXECVEAT
|
||||
|
@ -2027,6 +2027,7 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -117,6 +117,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.4 _Exit F
|
||||
GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
|
||||
GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
|
||||
|
@ -1874,6 +1874,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -2039,6 +2039,7 @@ GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1908,6 +1908,7 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -97,6 +97,11 @@
|
||||
implementation based on p{read,write}v and returning an error for
|
||||
non supported flags. */
|
||||
|
||||
/* Support for the renameat2 system call was added in kernel 3.15. */
|
||||
#if __LINUX_KERNEL_VERSION >= 0x030F00
|
||||
# define __ASSUME_RENAMEAT2
|
||||
#endif
|
||||
|
||||
/* Support for the execveat syscall was added in 3.19. */
|
||||
#if __LINUX_KERNEL_VERSION >= 0x031300
|
||||
# define __ASSUME_EXECVEAT 1
|
||||
|
@ -118,6 +118,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.4 _Exit F
|
||||
GLIBC_2.4 _IO_2_1_stderr_ D 0x98
|
||||
GLIBC_2.4 _IO_2_1_stdin_ D 0x98
|
||||
|
@ -1983,6 +1983,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -48,6 +48,11 @@
|
||||
# undef __ASSUME_SENDMMSG_SYSCALL
|
||||
#endif
|
||||
|
||||
/* Support for the renameat2 syscall was added in 3.17. */
|
||||
#if __LINUX_KERNEL_VERSION < 0x031100
|
||||
# undef __ASSUME_RENAMEAT2
|
||||
#endif
|
||||
|
||||
/* Support for the execveat syscall was added in 4.0. */
|
||||
#if __LINUX_KERNEL_VERSION < 0x040000
|
||||
# undef __ASSUME_EXECVEAT
|
||||
|
@ -2124,3 +2124,4 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
|
@ -1961,6 +1961,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1959,6 +1959,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1967,6 +1967,7 @@ GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1962,6 +1962,7 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -2165,3 +2165,4 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
|
@ -1987,6 +1987,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1991,6 +1991,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -2222,3 +2222,4 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
|
@ -117,6 +117,7 @@ GLIBC_2.27 wcstof32x_l F
|
||||
GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 _Exit F
|
||||
GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
|
||||
GLIBC_2.3 _IO_2_1_stdin_ D 0xe0
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
renameat (int oldfd, const char *old, int newfd, const char *new)
|
||||
__renameat (int oldfd, const char *old, int newfd, const char *new)
|
||||
{
|
||||
#ifdef __NR_renameat
|
||||
return INLINE_SYSCALL_CALL (renameat, oldfd, old, newfd, new);
|
||||
@ -30,3 +30,5 @@ renameat (int oldfd, const char *old, int newfd, const char *new)
|
||||
return INLINE_SYSCALL_CALL (renameat2, oldfd, old, newfd, new, 0);
|
||||
#endif
|
||||
}
|
||||
libc_hidden_def (__renameat)
|
||||
weak_alias (__renameat, renameat)
|
||||
|
44
sysdeps/unix/sysv/linux/renameat2.c
Normal file
44
sysdeps/unix/sysv/linux/renameat2.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* Linux implementation for renameat2 function.
|
||||
Copyright (C) 2018 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sysdep.h>
|
||||
|
||||
int
|
||||
renameat2 (int oldfd, const char *old, int newfd, const char *new,
|
||||
unsigned int flags)
|
||||
{
|
||||
#if !defined (__NR_renameat) || defined (__ASSUME_RENAMEAT2)
|
||||
return INLINE_SYSCALL_CALL (renameat2, oldfd, old, newfd, new, flags);
|
||||
#else
|
||||
if (flags == 0)
|
||||
return __renameat (oldfd, old, newfd, new);
|
||||
# ifdef __NR_renameat2
|
||||
/* For non-zero flags, try the renameat2 system call. */
|
||||
int ret = INLINE_SYSCALL_CALL (renameat2, oldfd, old, newfd, new, flags);
|
||||
if (ret != -1 || errno != ENOSYS)
|
||||
/* Preserve non-error/non-ENOSYS return values. */
|
||||
return ret;
|
||||
# endif
|
||||
/* No kernel (header) support for renameat2. All flags are
|
||||
unknown. */
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
@ -2094,3 +2094,4 @@ GLIBC_2.27 xencrypt F
|
||||
GLIBC_2.27 xprt_register F
|
||||
GLIBC_2.27 xprt_unregister F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
|
@ -1996,6 +1996,7 @@ GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1901,6 +1901,7 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -51,4 +51,9 @@
|
||||
/* sh only supports ipc syscall. */
|
||||
#undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
|
||||
|
||||
/* Support for the renameat2 syscall was added in 4.8. */
|
||||
#if __LINUX_KERNEL_VERSION < 0x040800
|
||||
# undef __ASSUME_RENAMEAT2
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1878,6 +1878,7 @@ GLIBC_2.27 wcstof64 F
|
||||
GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -41,6 +41,11 @@
|
||||
/* sparc only supports ipc syscall. */
|
||||
#undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
|
||||
|
||||
/* Support for the renameat2 syscall was added in 3.16. */
|
||||
#if __LINUX_KERNEL_VERSION < 0x031000
|
||||
# undef __ASSUME_RENAMEAT2
|
||||
#endif
|
||||
|
||||
/* SPARC kernel Kconfig does not define CONFIG_CLONE_BACKWARDS, however it
|
||||
has the same ABI as if it did, implemented by sparc-specific code
|
||||
(sparc_do_fork).
|
||||
|
@ -1990,6 +1990,7 @@ GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1931,6 +1931,7 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -1889,6 +1889,7 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
GLIBC_2.3 __ctype_b_loc F
|
||||
GLIBC_2.3 __ctype_tolower_loc F
|
||||
GLIBC_2.3 __ctype_toupper_loc F
|
||||
|
@ -2140,3 +2140,4 @@ GLIBC_2.27 wcstof64_l F
|
||||
GLIBC_2.27 wcstof64x F
|
||||
GLIBC_2.27 wcstof64x_l F
|
||||
GLIBC_2.28 fcntl64 F
|
||||
GLIBC_2.28 renameat2 F
|
||||
|
Reference in New Issue
Block a user