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
6 This fixes building trousers with musl
8 Signed-off-by: NoƩ Rubinstein <nrubinstein@aldebaran.com>
11 src/tspi/ps/tspps.c | 10 +++++-----
12 2 files changed, 9 insertions(+), 5 deletions(-)
14 diff --git a/configure.in b/configure.in
15 index fd3f5f1..e3d7acf 100644
18 @@ -145,6 +145,10 @@ else
19 AC_MSG_ERROR(["gtk", "openssl" and "none" are the only supported gui options for trousers])
22 +# Look for getpwent_r. If it is not found, getpwent will be used instead, with
23 +# an additional mutex.
24 +AC_CHECK_FUNC(getpwent_r, [AC_DEFINE(HAVE_GETPWENT_R)])
27 # The default port that the TCS daemon listens on
29 diff --git a/src/tspi/ps/tspps.c b/src/tspi/ps/tspps.c
30 index c6f9c3d..9d00d2a 100644
31 --- a/src/tspi/ps/tspps.c
32 +++ b/src/tspi/ps/tspps.c
35 static int user_ps_fd = -1;
36 static MUTEX_DECLARE_INIT(user_ps_lock);
37 -#if (defined (__FreeBSD__) || defined (__OpenBSD__))
38 +#ifndef HAVE_GETPWENT_R
39 static MUTEX_DECLARE_INIT(user_ps_path);
41 static struct flock fl;
42 @@ -60,7 +60,7 @@ get_user_ps_path(char **file)
44 char *file_name = NULL, *home_dir = NULL;
46 -#if (defined (__linux) || defined (linux) || defined(__GLIBC__))
47 +#ifdef HAVE_GETPWENT_R
51 @@ -72,7 +72,7 @@ get_user_ps_path(char **file)
52 *file = strdup(file_name);
53 return (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY);
55 -#if (defined (__FreeBSD__) || defined (__OpenBSD__))
56 +#ifndef HAVE_GETPWENT_R
57 MUTEX_LOCK(user_ps_path);
60 @@ -90,7 +90,7 @@ get_user_ps_path(char **file)
64 -#if (defined (__linux) || defined (linux) || defined(__GLIBC__))
65 +#ifdef HAVE_GETPWENT_R
66 rc = getpwent_r(&pw, buf, PASSWD_BUFSIZE, &pwp);
68 LogDebugFn("USER PS: Error getting path to home directory: getpwent_r: %s",
69 @@ -99,7 +99,7 @@ get_user_ps_path(char **file)
70 return TSPERR(TSS_E_INTERNAL_ERROR);
73 -#elif (defined (__FreeBSD__) || defined (__OpenBSD__))
75 if ((pwp = getpwent()) == NULL) {
76 LogDebugFn("USER PS: Error getting path to home directory: getpwent: %s",