From 8408f65252c23040e766b6a3ecde7bff390e2847 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 2 Dec 2004 15:32:54 +0000 Subject: Rework libpq threaded SIGPIPE handling to avoid interference with calling applications. This is done by blocking sigpipe in the libpq thread and using sigpending/sigwait to possibily discard any sigpipe we generated. --- src/interfaces/libpq/fe-print.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/interfaces/libpq/fe-print.c') diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index 832af2b3ac0..9992de533d7 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -10,7 +10,7 @@ * didn't really belong there. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.55 2004/11/09 15:57:57 petere Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.56 2004/12/02 15:32:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -91,7 +91,11 @@ PQprint(FILE *fout, int total_line_length = 0; int usePipe = 0; char *pagerenv; - +#ifdef ENABLE_THREAD_SAFETY + sigset_t osigset; + bool sigpipe_masked = false; + bool sigpipe_pending; +#endif #if !defined(ENABLE_THREAD_SAFETY) && !defined(WIN32) pqsigfunc oldsigpipehandler = NULL; #endif @@ -189,7 +193,8 @@ PQprint(FILE *fout, { usePipe = 1; #ifdef ENABLE_THREAD_SAFETY - pthread_setspecific(pq_thread_in_send, "t"); + pq_block_sigpipe(&osigset, &sigpipe_pending); + sigpipe_masked = true; #else #ifndef WIN32 oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN); @@ -311,7 +316,8 @@ PQprint(FILE *fout, pclose(fout); #endif #ifdef ENABLE_THREAD_SAFETY - pthread_setspecific(pq_thread_in_send, "f"); + if (sigpipe_masked) + pq_reset_sigpipe(&osigset, sigpipe_pending); #else #ifndef WIN32 pqsignal(SIGPIPE, oldsigpipehandler); -- cgit v1.2.3