0005-util-os_same_file_description-fix-unknown-linux-3.5-.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From b60974fac8a2f4c85cbb2ca788fc4ec3e81998f9 Mon Sep 17 00:00:00 2001
  2. From: Thomas Devoogdt <thomas.devoogdt@barco.com>
  3. Date: Tue, 17 Aug 2021 11:54:49 +0200
  4. Subject: [PATCH] util: os_same_file_description: fix unknown linux < 3.5
  5. syscall SYS_kcmp
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. https://man7.org/linux/man-pages/man2/kcmp.2.html
  10. The kcmp() system call first appeared in Linux 3.5.
  11. But was probably also not supported by all major platforms
  12. at that time. So fallback to the check that is done for windows.
  13. Signed-off-by: Thomas Devoogdt <thomas.devoogdt@barco.com>
  14. Acked-by: Yonggang Luo <luoyonggang@gmail.com>
  15. Acked-by: Michel Dänzer <mdaenzer@redhat.com>
  16. Upstream: https://gitlab.freedesktop.org/mesa/mesa/-/commit/3ef514982441ce496aa127611edd26b9867f4b95
  17. Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
  18. ---
  19. src/util/os_file.c | 18 ++++++------------
  20. 1 file changed, 6 insertions(+), 12 deletions(-)
  21. diff --git a/src/util/os_file.c b/src/util/os_file.c
  22. index 5fb30f2d908..464425a9b87 100644
  23. --- a/src/util/os_file.c
  24. +++ b/src/util/os_file.c
  25. @@ -202,29 +202,23 @@ os_read_file(const char *filename, size_t *size)
  26. /* copied from <linux/kcmp.h> */
  27. #define KCMP_FILE 0
  28. +#endif
  29. +
  30. int
  31. os_same_file_description(int fd1, int fd2)
  32. {
  33. +#ifdef SYS_kcmp
  34. pid_t pid = getpid();
  35. +#endif
  36. /* Same file descriptor trivially implies same file description */
  37. if (fd1 == fd2)
  38. return 0;
  39. +#ifdef SYS_kcmp
  40. return syscall(SYS_kcmp, pid, pid, KCMP_FILE, fd1, fd2);
  41. -}
  42. -
  43. #else
  44. -
  45. -int
  46. -os_same_file_description(int fd1, int fd2)
  47. -{
  48. - /* Same file descriptor trivially implies same file description */
  49. - if (fd1 == fd2)
  50. - return 0;
  51. -
  52. /* Otherwise we can't tell */
  53. return -1;
  54. -}
  55. -
  56. #endif
  57. +}
  58. --
  59. 2.34.1