diff options
author | Magnus Hagander <magnus@hagander.net> | 2008-05-16 18:30:53 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2008-05-16 18:30:53 +0000 |
commit | 1d8902678844701c246063c7547bddb5071cdef5 (patch) | |
tree | 92823a2437ebab3a89b61aecf169b9de69eecb53 /src/interfaces/libpq/fe-secure.c | |
parent | 0ff81a525e43d4afbd8b57a99b646b3461d9849e (diff) |
Implement error checking for pthreads calls in thread-safe mode. They really
should always succeed, but in the likely event of a failure we would
previously fall through *without locking* - the new code will exit(1).
Printing the error message on stderr will not work for all applications, but
it's better than nothing at all - and our API doesn't provide a way to return
the error to the caller.
Diffstat (limited to 'src/interfaces/libpq/fe-secure.c')
-rw-r--r-- | src/interfaces/libpq/fe-secure.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 4414baba4a8..2f72b0a5de4 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.104 2008/03/31 02:43:14 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.105 2008/05/16 18:30:53 mha Exp $ * * NOTES * [ Most of these notes are wrong/obsolete, but perhaps not all ] @@ -796,12 +796,21 @@ static void pq_lockingcallback(int mode, int n, const char *file, int line) { if (mode & CRYPTO_LOCK) - pthread_mutex_lock(&pq_lockarray[n]); + { + if (pthread_mutex_lock(&pq_lockarray[n])) + PGTHREAD_ERROR("failed to lock mutex"); + } else - pthread_mutex_unlock(&pq_lockarray[n]); + { + if (pthread_mutex_unlock(&pq_lockarray[n])) + PGTHREAD_ERROR("failed to unlock mutex"); + } } #endif /* ENABLE_THREAD_SAFETY */ +/* + * Also see similar code in fe-connect.c, default_threadlock() + */ static int init_ssl_system(PGconn *conn) { @@ -817,11 +826,15 @@ init_ssl_system(PGconn *conn) while (InterlockedExchange(&mutex_initlock, 1) == 1) /* loop, another thread own the lock */ ; if (init_mutex == NULL) - pthread_mutex_init(&init_mutex, NULL); + { + if (pthread_mutex_init(&init_mutex, NULL)) + return -1; + } InterlockedExchange(&mutex_initlock, 0); } #endif - pthread_mutex_lock(&init_mutex); + if (pthread_mutex_lock(&init_mutex)) + return -1; if (pq_initssllib && pq_lockarray == NULL) { @@ -836,7 +849,10 @@ init_ssl_system(PGconn *conn) return -1; } for (i = 0; i < CRYPTO_num_locks(); i++) - pthread_mutex_init(&pq_lockarray[i], NULL); + { + if (pthread_mutex_init(&pq_lockarray[i], NULL)) + return -1; + } CRYPTO_set_locking_callback(pq_lockingcallback); } |