Skip to content

Commit 109d7af

Browse files
committed
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.
1 parent 8b82a70 commit 109d7af

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.279 2004/08/11 18:06:01 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.280 2004/08/17 04:24:23 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -886,7 +886,7 @@ connectDBStart(PGconn *conn)
886886
static pthread_once_t check_sigpipe_once = PTHREAD_ONCE_INIT;
887887

888888
/* Check only on first connection request */
889-
pthread_once(&check_sigpipe_once, check_sigpipe_handler);
889+
pthread_once(&check_sigpipe_once, pq_check_sigpipe_handler);
890890
#endif
891891
#endif
892892

src/interfaces/libpq/fe-print.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* didn't really belong there.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.51 2004/04/19 17:42:59 momjian Exp $
13+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.52 2004/08/17 04:24:23 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -188,7 +188,7 @@ PQprint(FILE *fout,
188188
{
189189
usePipe = 1;
190190
#ifdef ENABLE_THREAD_SAFETY
191-
pthread_setspecific(thread_in_send, "t");
191+
pthread_setspecific(pq_thread_in_send, "t");
192192
#else
193193
#ifndef WIN32
194194
oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN);
@@ -310,7 +310,7 @@ PQprint(FILE *fout,
310310
pclose(fout);
311311
#endif
312312
#ifdef ENABLE_THREAD_SAFETY
313-
pthread_setspecific(thread_in_send, "f");
313+
pthread_setspecific(pq_thread_in_send, "f");
314314
#else
315315
#ifndef WIN32
316316
pqsignal(SIGPIPE, oldsigpipehandler);

src/interfaces/libpq/fe-secure.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.45 2004/07/12 14:23:28 momjian Exp $
14+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.46 2004/08/17 04:24:23 tgl Exp $
1515
*
1616
* NOTES
1717
* The client *requires* a valid server certificate. Since
@@ -152,7 +152,7 @@ static SSL_CTX *SSL_context = NULL;
152152

153153
#ifdef ENABLE_THREAD_SAFETY
154154
static void sigpipe_handler_ignore_send(int signo);
155-
pthread_key_t thread_in_send;
155+
pthread_key_t pq_thread_in_send = 0;
156156
#endif
157157

158158
/* ------------------------------------------------------------ */
@@ -367,7 +367,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
367367
ssize_t n;
368368

369369
#ifdef ENABLE_THREAD_SAFETY
370-
pthread_setspecific(thread_in_send, "t");
370+
pthread_setspecific(pq_thread_in_send, "t");
371371
#else
372372
#ifndef WIN32
373373
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
@@ -435,7 +435,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
435435
n = send(conn->sock, ptr, len, 0);
436436

437437
#ifdef ENABLE_THREAD_SAFETY
438-
pthread_setspecific(thread_in_send, "f");
438+
pthread_setspecific(pq_thread_in_send, "f");
439439
#else
440440
#ifndef WIN32
441441
pqsignal(SIGPIPE, oldsighandler);
@@ -1188,7 +1188,7 @@ PQgetssl(PGconn *conn)
11881188
* Check SIGPIPE handler and perhaps install our own.
11891189
*/
11901190
void
1191-
check_sigpipe_handler(void)
1191+
pq_check_sigpipe_handler(void)
11921192
{
11931193
pqsigfunc pipehandler;
11941194

@@ -1204,7 +1204,7 @@ check_sigpipe_handler(void)
12041204
* Create key first because the signal handler might be called
12051205
* right after being installed.
12061206
*/
1207-
pthread_key_create(&thread_in_send, NULL);
1207+
pthread_key_create(&pq_thread_in_send, NULL);
12081208
pqsignal(SIGPIPE, sigpipe_handler_ignore_send);
12091209
}
12101210
}
@@ -1236,8 +1236,8 @@ pqbool
12361236
PQinSend(void)
12371237
{
12381238
#ifdef ENABLE_THREAD_SAFETY
1239-
return (pthread_getspecific(thread_in_send) /* has it been set? */ &&
1240-
*(char *)pthread_getspecific(thread_in_send) == 't') ? true : false;
1239+
return (pthread_getspecific(pq_thread_in_send) /* has it been set? */ &&
1240+
*(char *)pthread_getspecific(pq_thread_in_send) == 't') ? true : false;
12411241
#else
12421242
/*
12431243
* No threading: our code ignores SIGPIPE around send().

src/interfaces/libpq/libpq-int.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.88 2004/05/31 18:42:40 tgl Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.89 2004/08/17 04:24:23 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -456,8 +456,8 @@ extern void pqsecure_close(PGconn *);
456456
extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
457457
extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
458458
#ifdef ENABLE_THREAD_SAFETY
459-
extern void check_sigpipe_handler(void);
460-
extern pthread_key_t thread_in_send;
459+
extern void pq_check_sigpipe_handler(void);
460+
extern pthread_key_t pq_thread_in_send;
461461
#endif
462462

463463
#ifdef USE_SSL

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy