Index: fe-secure.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-secure.c,v
retrieving revision 1.45
diff -u -r1.45 fe-secure.c
--- fe-secure.c	12 Jul 2004 14:23:28 -0000	1.45
+++ fe-secure.c	11 Aug 2004 12:49:35 -0000
@@ -153,6 +153,7 @@
 #ifdef ENABLE_THREAD_SAFETY
 static void sigpipe_handler_ignore_send(int signo);
 pthread_key_t thread_in_send;
+static pqsigfunc pipehandler;
 #endif
 
 /* ------------------------------------------------------------ */
@@ -1190,23 +1191,14 @@
 void
 check_sigpipe_handler(void)
 {
-	pqsigfunc pipehandler;
-
 	/*
 	 *	If the app hasn't set a SIGPIPE handler, define our own
 	 *	that ignores SIGPIPE on libpq send() and does SIG_DFL
 	 *	for other SIGPIPE cases.
 	 */
+	pthread_key_create(&thread_in_send, NULL);	
 	pipehandler = pqsignalinquire(SIGPIPE);
-	if (pipehandler == SIG_DFL)	/* not set by application */
-	{
-		/*
-		 *	Create key first because the signal handler might be called
-		 *	right after being installed.
-		 */
-		pthread_key_create(&thread_in_send, NULL);	
-		pqsignal(SIGPIPE, sigpipe_handler_ignore_send);
-	}
+	pqsignal(SIGPIPE, sigpipe_handler_ignore_send);
 }
 
 /*
@@ -1221,7 +1213,12 @@
 	 *	that caused the signal.
 	 */
 	if (!PQinSend())
-		exit(128 + SIGPIPE);	/* typical return value for SIG_DFL */
+	{
+	    if (pipehandler == SIG_DFL)	/* not set by application */
+		    exit(128 + SIGPIPE);	/* typical return value for SIG_DFL */
+		else
+		    (*pipehandler)(signo);      /* call original handler */
+	}
 }
 #endif
 #endif
