Commit 109d7aff authored by Tom Lane's avatar Tom Lane

Fix linking problem when enabling thread safety on Darwin: uninitialized

global variables are problematic on this platform.  Simplest solution
seems to be to initialize pthread key variable to 0.  Also, rename this
variable and check_sigpipe_handler to something involving "pq" to
avoid gratuitous pollution of application namespace.
parent 8b82a705
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.279 2004/08/11 18:06:01 tgl Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.280 2004/08/17 04:24:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -886,7 +886,7 @@ connectDBStart(PGconn *conn) ...@@ -886,7 +886,7 @@ connectDBStart(PGconn *conn)
static pthread_once_t check_sigpipe_once = PTHREAD_ONCE_INIT; static pthread_once_t check_sigpipe_once = PTHREAD_ONCE_INIT;
/* Check only on first connection request */ /* Check only on first connection request */
pthread_once(&check_sigpipe_once, check_sigpipe_handler); pthread_once(&check_sigpipe_once, pq_check_sigpipe_handler);
#endif #endif
#endif #endif
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* didn't really belong there. * didn't really belong there.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.51 2004/04/19 17:42:59 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.52 2004/08/17 04:24:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -188,7 +188,7 @@ PQprint(FILE *fout, ...@@ -188,7 +188,7 @@ PQprint(FILE *fout,
{ {
usePipe = 1; usePipe = 1;
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
pthread_setspecific(thread_in_send, "t"); pthread_setspecific(pq_thread_in_send, "t");
#else #else
#ifndef WIN32 #ifndef WIN32
oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN); oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN);
...@@ -310,7 +310,7 @@ PQprint(FILE *fout, ...@@ -310,7 +310,7 @@ PQprint(FILE *fout,
pclose(fout); pclose(fout);
#endif #endif
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
pthread_setspecific(thread_in_send, "f"); pthread_setspecific(pq_thread_in_send, "f");
#else #else
#ifndef WIN32 #ifndef WIN32
pqsignal(SIGPIPE, oldsigpipehandler); pqsignal(SIGPIPE, oldsigpipehandler);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.45 2004/07/12 14:23:28 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.46 2004/08/17 04:24:23 tgl Exp $
* *
* NOTES * NOTES
* The client *requires* a valid server certificate. Since * The client *requires* a valid server certificate. Since
...@@ -152,7 +152,7 @@ static SSL_CTX *SSL_context = NULL; ...@@ -152,7 +152,7 @@ static SSL_CTX *SSL_context = NULL;
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
static void sigpipe_handler_ignore_send(int signo); static void sigpipe_handler_ignore_send(int signo);
pthread_key_t thread_in_send; pthread_key_t pq_thread_in_send = 0;
#endif #endif
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
...@@ -367,7 +367,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len) ...@@ -367,7 +367,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
ssize_t n; ssize_t n;
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
pthread_setspecific(thread_in_send, "t"); pthread_setspecific(pq_thread_in_send, "t");
#else #else
#ifndef WIN32 #ifndef WIN32
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN); pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
...@@ -435,7 +435,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len) ...@@ -435,7 +435,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
n = send(conn->sock, ptr, len, 0); n = send(conn->sock, ptr, len, 0);
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
pthread_setspecific(thread_in_send, "f"); pthread_setspecific(pq_thread_in_send, "f");
#else #else
#ifndef WIN32 #ifndef WIN32
pqsignal(SIGPIPE, oldsighandler); pqsignal(SIGPIPE, oldsighandler);
...@@ -1188,7 +1188,7 @@ PQgetssl(PGconn *conn) ...@@ -1188,7 +1188,7 @@ PQgetssl(PGconn *conn)
* Check SIGPIPE handler and perhaps install our own. * Check SIGPIPE handler and perhaps install our own.
*/ */
void void
check_sigpipe_handler(void) pq_check_sigpipe_handler(void)
{ {
pqsigfunc pipehandler; pqsigfunc pipehandler;
...@@ -1204,7 +1204,7 @@ check_sigpipe_handler(void) ...@@ -1204,7 +1204,7 @@ check_sigpipe_handler(void)
* Create key first because the signal handler might be called * Create key first because the signal handler might be called
* right after being installed. * right after being installed.
*/ */
pthread_key_create(&thread_in_send, NULL); pthread_key_create(&pq_thread_in_send, NULL);
pqsignal(SIGPIPE, sigpipe_handler_ignore_send); pqsignal(SIGPIPE, sigpipe_handler_ignore_send);
} }
} }
...@@ -1236,8 +1236,8 @@ pqbool ...@@ -1236,8 +1236,8 @@ pqbool
PQinSend(void) PQinSend(void)
{ {
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
return (pthread_getspecific(thread_in_send) /* has it been set? */ && return (pthread_getspecific(pq_thread_in_send) /* has it been set? */ &&
*(char *)pthread_getspecific(thread_in_send) == 't') ? true : false; *(char *)pthread_getspecific(pq_thread_in_send) == 't') ? true : false;
#else #else
/* /*
* No threading: our code ignores SIGPIPE around send(). * No threading: our code ignores SIGPIPE around send().
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.88 2004/05/31 18:42:40 tgl Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.89 2004/08/17 04:24:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -456,8 +456,8 @@ extern void pqsecure_close(PGconn *); ...@@ -456,8 +456,8 @@ extern void pqsecure_close(PGconn *);
extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len); extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len); extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
#ifdef ENABLE_THREAD_SAFETY #ifdef ENABLE_THREAD_SAFETY
extern void check_sigpipe_handler(void); extern void pq_check_sigpipe_handler(void);
extern pthread_key_t thread_in_send; extern pthread_key_t pq_thread_in_send;
#endif #endif
#ifdef USE_SSL #ifdef USE_SSL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment