0005-libuuid-support-non-cached-scenarios-when-lpthread-i.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From eecaa2c0dda817eba2d493f6ddb42c39cf789fc2 Mon Sep 17 00:00:00 2001
  2. From: Karel Zak <kzak@redhat.com>
  3. Date: Mon, 27 Jan 2025 14:28:36 +0100
  4. Subject: [PATCH] libuuid: support non-cached scenarios (when -lpthread is
  5. unavailable)
  6. This patch makes the dependence on pthread optional for libuuid. In
  7. certain cases, such as Buildroot Linux, uClibc-ng, and very low
  8. resource systems, libpthread may be unavailable.
  9. If libuuid is compiled without pthread, it will not use a local cache
  10. and will instead request a UUID from uuidd for each call. This may
  11. result in less efficient performance, but the UUIDs generated will
  12. still be unique and reliable.
  13. On minimalistic systems, it is highly likely that uuidd will not be
  14. installed, making this change important for portability and robust
  15. code.
  16. Upstream: https://github.com/util-linux/util-linux/pull/3383
  17. Addresses: https://github.com/util-linux/util-linux/pull/3375
  18. Signed-off-by: Karel Zak <kzak@redhat.com>
  19. Signed-off-by: Julien Olivain <ju.o@free.fr>
  20. ---
  21. libuuid/src/gen_uuid.c | 18 +++++++++++++++---
  22. 1 file changed, 15 insertions(+), 3 deletions(-)
  23. diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c
  24. index 69712267f..1ed82b46b 100644
  25. --- a/libuuid/src/gen_uuid.c
  26. +++ b/libuuid/src/gen_uuid.c
  27. @@ -80,7 +80,10 @@
  28. #if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
  29. #include <sys/syscall.h>
  30. #endif
  31. -#include <pthread.h>
  32. +#ifdef HAVE_LIBPTHREAD
  33. +# include <pthread.h>
  34. +#endif
  35. +
  36. #include <signal.h>
  37. #include "all-io.h"
  38. @@ -580,8 +583,7 @@ int __uuid_generate_time_cont(uuid_t out, int *num, uint32_t cont_offset)
  39. * If neither of these is possible (e.g. because of insufficient permissions), it generates
  40. * the UUID anyway, but returns -1. Otherwise, returns 0.
  41. */
  42. -
  43. -/* thread local cache for uuidd based requests */
  44. +#ifdef HAVE_LIBPTHREAD
  45. THREAD_LOCAL struct {
  46. int num;
  47. int cache_size;
  48. @@ -597,8 +599,10 @@ static void reset_uuidd_cache(void)
  49. memset(&uuidd_cache, 0, sizeof(uuidd_cache));
  50. uuidd_cache.cache_size = CS_MIN;
  51. }
  52. +#endif /* HAVE_LIBPTHREAD */
  53. static int uuid_generate_time_generic(uuid_t out) {
  54. +#ifdef HAVE_LIBPTHREAD
  55. static volatile sig_atomic_t atfork_registered;
  56. time_t now;
  57. @@ -651,6 +655,14 @@ static int uuid_generate_time_generic(uuid_t out) {
  58. return 0;
  59. }
  60. +#else /* !HAVE_LIBPTHREAD */
  61. + {
  62. + int num = 1;
  63. + if (get_uuid_via_daemon(UUIDD_OP_TIME_UUID, out, &num) == 0)
  64. + return 0;
  65. + }
  66. +#endif /* HAVE_LIBPTHREAD */
  67. +
  68. return __uuid_generate_time(out, NULL);
  69. }
  70. --
  71. 2.48.1