On Mon, 2013-08-12 at 10:49 -0400, Stephen Frost wrote: > > Alternatively, if we want to just print an error message and > proceed, we > > should put the strerror based on the return value into the message. > > That could certainly be added.
Here is a patch for that. I also adjusted the message wording to be more in line with project style. > Should we also be adding an > error message+strerror in cases where pthread_mutex_unlock() fails for > some reason? > Ideally yes, I think. But it's probably less urgent, because it if fails the next lock request will probably error?
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index b16968b..3bd0113 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -256,14 +256,18 @@ struct sigpipe_info /* 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 @@ -1115,10 +1119,12 @@ struct sigpipe_info * 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 @@ -1333,10 +1339,12 @@ struct sigpipe_info 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
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers