Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Improve handling of pthread_mutex_lock error case
authorStephen Frost <sfrost@snowman.net>
Thu, 1 Aug 2013 19:42:07 +0000 (15:42 -0400)
committerStephen Frost <sfrost@snowman.net>
Thu, 1 Aug 2013 19:43:49 +0000 (15:43 -0400)
We should really be reporting a useful error along with returning
a valid return code if pthread_mutex_lock() throws an error for
some reason.  Add that and back-patch to 9.0 as the prior patch.

Pointed out by Alvaro Herrera

src/interfaces/libpq/fe-secure.c

index 805d4ec49d366f7d75d7d3a80a22c71af71eab44..22e0be7f06128e24ef88f882561288c494409595 100644 (file)
@@ -262,7 +262,11 @@ pqsecure_open_client(PGconn *conn)
 
 #ifdef ENABLE_THREAD_SAFETY
        if (pthread_mutex_lock(&ssl_config_mutex))
-           return -1;
+       {
+           printfPQExpBuffer(&conn->errorMessage,
+                  libpq_gettext("unable to acquire mutex\n"));
+           return PGRES_POLLING_FAILED;
+       }
 #endif
        /* Create a connection-specific SSL object */
        if (!(conn->ssl = SSL_new(SSL_context)) ||
@@ -1111,7 +1115,11 @@ initialize_SSL(PGconn *conn)
         */
 #ifdef ENABLE_THREAD_SAFETY
        if (pthread_mutex_lock(&ssl_config_mutex))
+       {
+           printfPQExpBuffer(&conn->errorMessage,
+                  libpq_gettext("unable to acquire mutex\n"));
            return -1;
+       }
 #endif
        if (SSL_CTX_use_certificate_chain_file(SSL_context, fnbuf) != 1)
        {
@@ -1325,7 +1333,11 @@ initialize_SSL(PGconn *conn)
 
 #ifdef ENABLE_THREAD_SAFETY
        if (pthread_mutex_lock(&ssl_config_mutex))
+       {
+           printfPQExpBuffer(&conn->errorMessage,
+                  libpq_gettext("unable to acquire mutex\n"));
            return -1;
+       }
 #endif
        if (SSL_CTX_load_verify_locations(SSL_context, fnbuf, NULL) != 1)
        {