util: use F_DUPFD_QUERY on Linux
F_DUPFD_QUERY has been introduced in 6.10 exactly for the purpose of telling if 2 fd points at the same file description so use it first. If it's not supported, we'll get r=-1 and errno=EINVAL, and we can fallback on KCMP or epoll. Acked-by: Simona Vetter <simona.vetter@ffwll.ch> Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34447>
This commit is contained in:
committed by
Marge Bot
parent
17e286529b
commit
c0c95dc845
+15
-2
@@ -29,6 +29,9 @@
|
||||
#ifndef F_DUPFD_CLOEXEC
|
||||
#define F_DUPFD_CLOEXEC 1030
|
||||
#endif
|
||||
#ifndef F_DUPFD_QUERY
|
||||
#define F_DUPFD_QUERY 1027
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -240,6 +243,18 @@ os_same_file_description(int fd1, int fd2)
|
||||
if (fd1 == fd2)
|
||||
return 0;
|
||||
|
||||
#if DETECT_OS_LINUX
|
||||
/* Use F_DUPFD_QUERY if available. */
|
||||
int r = fcntl(fd1, F_DUPFD_QUERY, fd2);
|
||||
|
||||
if (r < 0) {
|
||||
if (errno == EBADF)
|
||||
return 1;
|
||||
} else {
|
||||
return r == 1 ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SYS_kcmp
|
||||
return syscall(SYS_kcmp, pid, pid, KCMP_FILE, fd1, fd2);
|
||||
#elif DETECT_OS_DRAGONFLY || DETECT_OS_FREEBSD
|
||||
@@ -269,8 +284,6 @@ os_same_file_description(int fd1, int fd2)
|
||||
|
||||
return (fd1_kfile < fd2_kfile) | ((fd1_kfile > fd2_kfile) << 1);
|
||||
#elif DETECT_OS_LINUX
|
||||
int r;
|
||||
|
||||
int efd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (efd < 0)
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user