SIGPIPE handling, take two.

From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: SIGPIPE handling, take two.
Date: 2003-11-02 18:40:29
Message-ID: 3FA54F9D.3070802@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

pqsecure_write tries to catch SIGPIPE signals generated by network
disconnects by setting the signal handler to SIG_IGN. The current
approach causes several problems:
- it always sets SA_RESTART when it restores the old handler.
- it's not reliable for multi threaded apps, because another thread
could change the signal handler inbetween.
- it's slow, because after setting a signal handler to SIG_IGN the
kernel must enumerate all threads and clear all pending signals (at
least FreeBSD-5.1 and linux-2.6 do that. Earlier linux kernels don't -
their signal handling is known to be broken for multithreaded apps).

Initially I proposed a new option for PQconnectdb, but Tom didn't like
that. The attached patch autodetects if it should set the signal
handler, Tom proposed that. The code doesn't try to check if the signal
is "handled" by blocking it, because I haven't figured out how to check
that: sigprocmask is undefined for multithreaded apps and calling
pthread_sigmask would force every libpq user to link against libpthread.

--
Manfred

Attachment Content-Type Size
patch-autopipe text/plain 3.3 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Markus Bertheau 2003-11-02 18:43:12 psql: \dg and groups for \du
Previous Message Michael Mauger 2003-11-02 01:36:56 Re: Proposal: psql force prompting on notty