0002-Check-that-getpwent_r-is-available-before-using-it.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From 9e42c405f30d2b52d019598436ea346ef8586f43 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?No=C3=A9=20Rubinstein?= <nrubinstein@aldebaran.com>
  3. Date: Wed, 24 Aug 2016 18:55:25 +0200
  4. Subject: [PATCH] Check that getpwent_r is available before using it
  5. This fixes building trousers with musl
  6. Signed-off-by: Noé Rubinstein <nrubinstein@aldebaran.com>
  7. [Bernd: Rebased for version 0.3.14]
  8. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  9. ---
  10. configure.ac | 4 ++++
  11. src/tspi/ps/tspps.c | 10 +++++-----
  12. 2 files changed, 9 insertions(+), 5 deletions(-)
  13. diff --git a/configure.in b/configure.in
  14. index fd3f5f1..e3d7acf 100644
  15. --- a/configure.ac
  16. +++ b/configure.ac
  17. @@ -145,6 +145,10 @@ else
  18. AC_MSG_ERROR(["gtk", "openssl" and "none" are the only supported gui options for trousers])
  19. fi
  20. +# Look for getpwent_r. If it is not found, getpwent will be used instead, with
  21. +# an additional mutex.
  22. +AC_CHECK_FUNC(getpwent_r, [AC_DEFINE(HAVE_GETPWENT_R)])
  23. +
  24. #
  25. # The default port that the TCS daemon listens on
  26. #
  27. diff --git a/src/tspi/ps/tspps.c b/src/tspi/ps/tspps.c
  28. index c6f9c3d..9d00d2a 100644
  29. --- a/src/tspi/ps/tspps.c
  30. +++ b/src/tspi/ps/tspps.c
  31. @@ -45,7 +45,7 @@
  32. static int user_ps_fd = -1;
  33. static MUTEX_DECLARE_INIT(user_ps_lock);
  34. -#if (defined (__FreeBSD__) || defined (__OpenBSD__))
  35. +#ifndef HAVE_GETPWENT_R
  36. static MUTEX_DECLARE_INIT(user_ps_path);
  37. #endif
  38. static struct flock fl;
  39. @@ -60,7 +60,7 @@ get_user_ps_path(char **file)
  40. TSS_RESULT result;
  41. char *file_name = NULL, *home_dir = NULL;
  42. struct passwd *pwp;
  43. -#if (defined (__linux) || defined (linux) || defined(__GLIBC__))
  44. +#ifdef HAVE_GETPWENT_R
  45. struct passwd pw;
  46. #endif
  47. struct stat stat_buf;
  48. @@ -72,7 +72,7 @@ get_user_ps_path(char **file)
  49. *file = strdup(file_name);
  50. return (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY);
  51. }
  52. -#if (defined (__FreeBSD__) || defined (__OpenBSD__))
  53. +#ifndef HAVE_GETPWENT_R
  54. MUTEX_LOCK(user_ps_path);
  55. #endif
  56. @@ -90,7 +90,7 @@ get_user_ps_path(char **file)
  57. #else
  58. setpwent();
  59. while (1) {
  60. -#if (defined (__linux) || defined (linux) || defined(__GLIBC__))
  61. +#ifdef HAVE_GETPWENT_R
  62. rc = getpwent_r(&pw, buf, PASSWD_BUFSIZE, &pwp);
  63. if (rc) {
  64. LogDebugFn("USER PS: Error getting path to home directory: getpwent_r: %s",
  65. @@ -99,7 +99,7 @@ get_user_ps_path(char **file)
  66. return TSPERR(TSS_E_INTERNAL_ERROR);
  67. }
  68. -#elif (defined (__FreeBSD__) || defined (__OpenBSD__))
  69. +#else
  70. if ((pwp = getpwent()) == NULL) {
  71. LogDebugFn("USER PS: Error getting path to home directory: getpwent: %s",
  72. strerror(rc));
  73. --
  74. 2.1.4