pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid calling gettext() in signal handlers.
Date: Mon, 17 Jan 2022 18:30:27 +0000
Message-ID: <E1n9Wlv-0004VX-EC@gemulon.postgresql.org> (raw)

Avoid calling gettext() in signal handlers.

It seems highly unlikely that gettext() can be relied on to be
async-signal-safe.  psql used to understand that, but someone got
it wrong long ago in the src/bin/scripts/ version of handle_sigint,
and then the bad idea was perpetuated when those two versions were
unified into src/fe_utils/cancel.c.

I'm unsure why there have not been field complaints about this
... maybe gettext() is signal-safe once it's translated at least
one message?  But we have no business assuming any such thing.

In cancel.c (v13 and up), I preserved our ability to localize
"Cancel request sent" messages by invoking gettext() before
the signal handler is set up.  In earlier branches I just made
src/bin/scripts/ not localize those messages, as psql did then.

(Just for extra unsafety, the src/bin/scripts/ version was
invoking fprintf() from a signal handler.  Sigh.)

Noted while fixing signal-safety issues in PQcancel() itself.
Back-patch to all supported branches.

Discussion: https://postgr.es/m/2937814.1641960929@sss.pgh.pa.us

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/62bfa554b285f34e7d3ec3675fa87ba0d71f7268

Modified Files
--------------
src/bin/scripts/common.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1n9Wlv-0004VX-EC@gemulon.postgresql.org>
Permalink:  ../E1n9Wlv-0004VX-EC@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1n9Wlv-0004VX-EC@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Avoid calling gettext() in signal handlers.
  In-Reply-To: <E1n9Wlv-0004VX-EC@gemulon.postgresql.org>
  References: <E1n9Wlv-0004VX-EC@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox