postgresql/src/include
Andrew Dunstan 3e2a1496ba Rework signal handler infrastructure to pass sender info as argument.
Commit 095c9d4cf06 added errdetail() reporting of the PID and UID of
the process that sent a termination signal.  However, as noted by
Andres Freund, the implementation had architectural problems:

1. wrapper_handler() in pqsignal.c contained SIGTERM-specific logic
   (setting ProcDieSenderPid/Uid), violating its role as a generic
   signal dispatch wrapper.

2. Using globals to pass sender info between wrapper_handler and the
   real handler is unsafe when signals nest on some platforms.

3. The syncrep.c errdetail used psprintf() to conditionally embed
   text via %s, breaking translatability.

Adopt the approach proposed by Andres Freund: introduce a
pg_signal_info struct that is passed as an argument to all signal
handlers via the SIGNAL_ARGS macro.  wrapper_handler populates it
from siginfo_t when SA_SIGINFO is available, or with zeros otherwise.
This keeps wrapper_handler fully generic and avoids any globals for
passing signal metadata.

Since pqsigfunc now has a different signature from the system's
signal handler type, SIG_IGN and SIG_DFL can no longer be passed
directly to pqsignal().  Introduce PG_SIG_IGN and PG_SIG_DFL macros
that cast to the new pqsigfunc type, and update all call sites.
The legacy pqsignal() in libpq retains its original signature via
a local typedef.

Only die() reads pg_siginfo today, copying the sender PID/UID into
ProcDieSenderPid/Uid for later use by ProcessInterrupts().  Only the
first SIGTERM's sender info is recorded.

Also fix the syncrep.c translatability issue by using separate ereport
calls with complete, independently translatable errdetail strings.

Also make the psql TAP test require the DETAIL line on platforms with
SA_SIGINFO, rather than making it unconditionally optional.

On Windows, pg_signal_info uses uint32_t for pid and uid fields
since pid_t/uid_t are not available early enough in the include
chain.  The Windows signal dispatch in pgwin32_dispatch_queued_signals()
passes a zeroed pg_signal_info to handlers.

Author: Andres Freund <andres@anarazel.de>
Author: Jakub Wartak <jakub.wartak@enterprisedb.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/cwyyryh2veejuxbj5ifzyaejw7jhhqc5mrdeq56xckknsdecn2@6hzfcxde2nm5
Discussion: https://postgr.es/m/jygesyr7mwg7ovdbxpmjvvbi3hccptpkcreqb645h7f56puwbz@hmkkwi3melfe
2026-04-15 07:30:34 -04:00
..
access Add EXPLAIN (IO) infrastructure with BitmapHeapScan support 2026-04-07 22:33:34 +02:00
archive Update copyright for 2026 2026-01-01 13:24:10 -05:00
backup Update copyright for 2026 2026-01-01 13:24:10 -05:00
bootstrap Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
catalog Reduce presence of syscache.h in src/include/ 2026-04-09 08:49:36 +09:00
commands Explicitly forbid non-top-level WAIT FOR execution 2026-04-13 14:04:52 +03:00
common Add log file support to logging.c 2026-04-13 10:44:02 +02:00
datatype Update copyright for 2026 2026-01-01 13:24:10 -05:00
executor instrumentation: Allocate query level instrumentation in ExecutorStart 2026-04-08 00:06:45 -04:00
fe_utils Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
foreign Add support for importing statistics from remote servers. 2026-04-08 19:15:00 +09:00
jit jit: No backport::SectionMemoryManager for LLVM 22. 2026-04-03 14:55:11 +13:00
lib Use standard C23 and C++ attributes if available 2026-04-01 08:15:02 +02:00
libpq Remove RADIUS support. 2026-04-08 22:38:43 +12:00
mb Remove MULE_INTERNAL encoding. 2026-04-08 17:40:06 +12:00
nodes Add EXPLAIN (IO) instrumentation for TidRangeScan 2026-04-07 23:25:05 +02:00
optimizer Fix var_is_nonnullable() to handle invalid NOT NULL constraints 2026-04-15 09:38:56 +09:00
parser Mark JumbleState as a const in the post_parse_analyze hook 2026-04-07 15:22:49 +09:00
partitioning Update copyright for 2026 2026-01-01 13:24:10 -05:00
pch Update copyright for 2026 2026-01-01 13:24:10 -05:00
port Allow retrieving x86 TSC frequency/flags from CPUID 2026-04-07 13:00:24 -04:00
portability Add missing PGDLLIMPORT markings 2026-04-08 15:49:33 +02:00
postmaster Convert all remaining subsystems to use the new shmem allocation API 2026-04-06 02:13:10 +03:00
regex Update copyright for 2026 2026-01-01 13:24:10 -05:00
replication Adjust log level of logical decoding messages by context 2026-04-10 22:59:34 +09:00
rewrite Add some const qualifiers enabled by typeof_unqual change on copyObject 2026-03-19 06:35:54 +01:00
snowball Update to latest Snowball sources. 2026-01-05 15:22:37 -05:00
statistics Add support for importing statistics from remote servers. 2026-04-08 19:15:00 +09:00
storage aio: Adjust I/O worker pool automatically. 2026-04-08 19:08:32 +12:00
tcop SQL Property Graph Queries (SQL/PGQ) 2026-03-16 10:14:18 +01:00
tsearch Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
utils Fix var_is_nonnullable() to handle invalid NOT NULL constraints 2026-04-15 09:38:56 +09:00
.gitignore Use <stdint.h> and <inttypes.h> for c.h integers. 2024-12-04 15:05:38 +13:00
c.h Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
fmgr.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
funcapi.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
getopt_long.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
Makefile Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:39 +09:00
meson.build Ensure that all three build methods install the same set of files. 2026-02-16 15:20:15 -05:00
miscadmin.h Add missing PGDLLIMPORT markings 2026-04-08 15:49:33 +02:00
pg_config.h.in Add errdetail() with PID and UID about source of termination signal. 2026-04-07 10:22:33 -04:00
pg_config_manual.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_getopt.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_trace.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgstat.h Fix double-free in pg_stat_autovacuum_scores. 2026-04-09 13:07:06 -05:00
pgtar.h Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
pgtime.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
port.h Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
postgres.h Remove Int8GetDatum function 2026-03-11 10:46:08 +01:00
postgres_ext.h Move pg_int64 back to postgres_ext.h 2025-09-16 10:48:56 +02:00
postgres_fe.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
varatt.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
windowapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00