0001-lib-Escape-usage-of-strerror_l-if-it-doesn-t-exist-i.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From 098a4cc35b0da4438b8b67a914edecebef5bb6a9 Mon Sep 17 00:00:00 2001
  2. From: Alexey Brodkin <abrodkin@synopsys.com>
  3. Date: Fri, 10 Mar 2017 13:22:14 +0300
  4. Subject: [PATCH] lib: Escape usage of strerror_l() if it doesn't exist in libc
  5. uClibc doesn't implement strerror_l() and thus libnl starting from
  6. 3.2.29 couldn't be compiled with it any longer.
  7. To work-around that problem we'll just do a check on strerror_l()
  8. availability during configuration and if it's not there just fall back
  9. to locale-less strerror().
  10. Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
  11. Cc: Andre Draszik <adraszik@tycoint.com>
  12. Cc: Thomas Haller <thaller@redhat.com>
  13. ---
  14. This patch is now accepted upstream and will be a part of the next libnl
  15. release, see
  16. https://github.com/thom311/libnl/commit/e15966ac7f3b43df2acf869f98089762807d0568
  17. configure.ac | 2 ++
  18. lib/utils.c | 8 +++++++-
  19. src/lib/utils.c | 6 ++++++
  20. 3 files changed, 15 insertions(+), 1 deletion(-)
  21. diff --git a/configure.ac b/configure.ac
  22. index 68b285e5b15c..2739b997ee3a 100644
  23. --- a/configure.ac
  24. +++ b/configure.ac
  25. @@ -121,6 +121,8 @@ fi
  26. AC_CONFIG_SUBDIRS([doc])
  27. +AC_CHECK_FUNCS([strerror_l])
  28. +
  29. AC_CONFIG_FILES([
  30. Makefile
  31. libnl-3.0.pc
  32. diff --git a/lib/utils.c b/lib/utils.c
  33. index fb350d13fd2f..06273c5b291e 100644
  34. --- a/lib/utils.c
  35. +++ b/lib/utils.c
  36. @@ -30,7 +30,9 @@
  37. #include <netlink/utils.h>
  38. #include <linux/socket.h>
  39. #include <stdlib.h> /* exit() */
  40. +#ifdef HAVE_STRERROR_L
  41. #include <locale.h>
  42. +#endif
  43. /**
  44. * Global variable indicating the desired level of debugging output.
  45. @@ -123,9 +125,10 @@ int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *))
  46. const char *nl_strerror_l(int err)
  47. {
  48. + const char *buf;
  49. +#ifdef HAVE_STRERROR_L
  50. int errno_save = errno;
  51. locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0);
  52. - const char *buf;
  53. if (loc == (locale_t)0) {
  54. if (errno == ENOENT)
  55. @@ -140,6 +143,9 @@ const char *nl_strerror_l(int err)
  56. }
  57. errno = errno_save;
  58. +#else
  59. + buf = strerror(err);
  60. +#endif
  61. return buf;
  62. }
  63. /** @endcond */
  64. diff --git a/src/lib/utils.c b/src/lib/utils.c
  65. index 5878f279c364..feb1d4ef4056 100644
  66. --- a/src/lib/utils.c
  67. +++ b/src/lib/utils.c
  68. @@ -81,6 +81,7 @@ void nl_cli_fatal(int err, const char *fmt, ...)
  69. fprintf(stderr, "\n");
  70. } else {
  71. char *buf;
  72. +#ifdef HAVE_STRERROR_L
  73. locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0);
  74. if (loc == (locale_t)0) {
  75. if (errno == ENOENT)
  76. @@ -91,9 +92,14 @@ void nl_cli_fatal(int err, const char *fmt, ...)
  77. }
  78. if (loc != (locale_t)0)
  79. buf = strerror_l(err, loc);
  80. +#else
  81. + buf = strerror(err);
  82. +#endif
  83. fprintf(stderr, "%s\n", buf);
  84. +#ifdef HAVE_STRERROR_L
  85. if (loc != (locale_t)0)
  86. freelocale(loc);
  87. +#endif
  88. }
  89. exit(abs(err));
  90. --
  91. 2.7.4