From b94c6c691e86a1d9c2a98e935f661c95924d8f37 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 17 Aug 2013 21:46:32 -0400 Subject: [PATCH] libpq: Report strerror on pthread_mutex_lock() failure --- src/interfaces/libpq/fe-secure.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index ba063a09ce..2ff229c683 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -257,14 +257,18 @@ pqsecure_open_client(PGconn *conn) /* First time through? */ if (conn->ssl == NULL) { +#ifdef ENABLE_THREAD_SAFETY + int rc; +#endif + /* We cannot use MSG_NOSIGNAL to block SIGPIPE when using SSL */ conn->sigpipe_flag = false; #ifdef ENABLE_THREAD_SAFETY - if (pthread_mutex_lock(&ssl_config_mutex)) + if ((rc = pthread_mutex_lock(&ssl_config_mutex))) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("unable to acquire mutex\n")); + libpq_gettext("could not acquire mutex: %s\n"), strerror(rc)); return PGRES_POLLING_FAILED; } #endif @@ -1116,10 +1120,12 @@ initialize_SSL(PGconn *conn) * SSL_context struct. */ #ifdef ENABLE_THREAD_SAFETY - if (pthread_mutex_lock(&ssl_config_mutex)) + int rc; + + if ((rc = pthread_mutex_lock(&ssl_config_mutex))) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("unable to acquire mutex\n")); + libpq_gettext("could not acquire mutex: %s\n"), strerror(rc)); return -1; } #endif @@ -1334,10 +1340,12 @@ initialize_SSL(PGconn *conn) X509_STORE *cvstore; #ifdef ENABLE_THREAD_SAFETY - if (pthread_mutex_lock(&ssl_config_mutex)) + int rc; + + if ((rc = pthread_mutex_lock(&ssl_config_mutex))) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("unable to acquire mutex\n")); + libpq_gettext("could not acquire mutex: %s\n"), strerror(rc)); return -1; } #endif -- 2.40.0