Re: What (not) to do in signal handlers - Mailing list pgsql-hackers

From Tom Lane
Subject Re: What (not) to do in signal handlers
Date
Msg-id 21805.992553058@sss.pgh.pa.us
Whole thread Raw
In response to Re: What (not) to do in signal handlers  (Doug McNaught <doug@wireboard.com>)
Responses Re: What (not) to do in signal handlers  (ncm@zembu.com (Nathan Myers))
List pgsql-hackers
Doug McNaught <doug@wireboard.com> writes:
> Tom Lane <tgl@sss.pgh.pa.us> writes:
>> Hm.  That's one way, but is it really any cleaner than our existing
>> technique?  Since you still need to assume you can do a system call
>> in a signal handler, it doesn't seem like a real gain in
>> bulletproofness to me.

> Doing write() in a signal handler is safe; doing fprintf() (and
> friends) is not.

If we were calling the signal handlers from random places, then I'd
agree.  But we're not: we use sigblock to ensure that signals are only
serviced at the place in the postmaster main loop where select() is
called.  So there's no actual risk of reentrant use of non-reentrant
library functions.

Please recall that in practice the postmaster is extremely reliable.
The single bug we have seen with the signal handlers in recent releases
was the problem that they were clobbering errno, which was easily fixed
by saving/restoring errno.  This same bug would have arisen (though at
such low probability we'd likely never have solved it) in a signal
handler that only invoked write().  So I find it difficult to buy the
argument that there's any net gain in robustness to be had here.

In short: this code isn't broken, and so I'm not convinced we should
"fix" it.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Doug McNaught
Date:
Subject: Re: What (not) to do in signal handlers
Next
From: ncm@zembu.com (Nathan Myers)
Date:
Subject: Re: What (not) to do in signal handlers