diff options
author | Bruce Momjian <bruce@momjian.us> | 2004-12-02 15:32:54 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2004-12-02 15:32:54 +0000 |
commit | 8408f65252c23040e766b6a3ecde7bff390e2847 (patch) | |
tree | 4db202b3d10eab659e3d8c9805691523c9a5555e /src/interfaces/libpq/fe-print.c | |
parent | e02ef267fc3d41cbba41b2bf404d18a936d28691 (diff) | |
download | postgresql-8408f65252c23040e766b6a3ecde7bff390e2847.tar.gz postgresql-8408f65252c23040e766b6a3ecde7bff390e2847.zip |
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.
Diffstat (limited to 'src/interfaces/libpq/fe-print.c')
-rw-r--r-- | src/interfaces/libpq/fe-print.c | 14 |
1 files changed, 10 insertions, 4 deletions
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); |