postgresql/src/include/utils
Nathan Bossart 97550c0711 Avoid calling proc_exit() in processes forked by system().
The SIGTERM handler for the startup process immediately calls
proc_exit() for the duration of the restore_command, i.e., a call
to system().  This system() call forks a new process to execute the
shell command, and this child process inherits the parent's signal
handlers.  If both the parent and child processes receive SIGTERM,
both will attempt to call proc_exit().  This can end badly.  For
example, both processes will try to remove themselves from the
PGPROC shared array.

To fix this problem, this commit adds a check in
StartupProcShutdownHandler() to see whether MyProcPid == getpid().
If they match, this is the parent process, and we can proc_exit()
like before.  If they do not match, this is a child process, and we
just emit a message to STDERR (in a signal safe manner) and
_exit(), thereby skipping any problematic exit callbacks.

This commit also adds checks in proc_exit(), ProcKill(), and
AuxiliaryProcKill() that verify they are not being called within
such child processes.

Suggested-by: Andres Freund
Reviewed-by: Thomas Munro, Andres Freund
Discussion: https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyz
Discussion: https://postgr.es/m/20230223231503.GA743455%40nathanxps13
Backpatch-through: 11
2023-10-17 10:41:48 -05:00
..
.gitignore Generate automatically code and documentation related to wait events 2023-07-05 10:53:11 +09:00
acl.h Harden has_xxx_privilege() functions against concurrent object drops. 2023-10-14 14:49:50 -04:00
aclchk_internal.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
array.h Allow parallel aggregate on string_agg and array_agg 2023-01-23 17:35:01 +13:00
arrayaccess.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
ascii.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
attoptcache.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
backend_progress.h Add new parallel message type to progress reporting. 2023-07-11 12:33:54 +09:00
backend_status.h Use actual backend IDs in pg_stat_get_backend_subxact(). 2023-08-30 14:47:01 -07:00
builtins.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
bytea.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
cash.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
catcache.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
combocid.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
conffiles.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
date.h Add back SQLValueFunction for SQL keywords 2023-05-17 10:19:17 +09:00
datetime.h Refactor datetime functions' timezone lookup code to reduce duplication. 2023-03-17 17:47:19 -04:00
datum.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
dsa.h Avoid type cheats for invalid dsa_handles and dshash_table_handles. 2023-01-25 11:48:38 -05:00
dynahash.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
elog.h Avoid calling proc_exit() in processes forked by system(). 2023-10-17 10:41:48 -05:00
evtcache.h Add support event triggers on authenticated login 2023-10-16 03:18:22 +03:00
expandeddatum.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
expandedrecord.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
float.h Doc: improve commentary about providing our own definitions of M_PI. 2023-01-08 16:25:33 -05:00
fmgrtab.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
formatting.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
freepage.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
geo_decls.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
guc.h Transform proconfig for faster execution. 2023-08-10 12:43:53 -07:00
guc_hooks.h Improve the naming in wal_sync_method code. 2023-10-13 15:16:45 -05:00
guc_tables.h Minor GUC code refactoring. 2023-01-27 12:13:41 -05:00
help_config.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
hsearch.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
index_selfuncs.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
inet.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
inval.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
json.h Add const to values and nulls arguments 2023-10-10 07:50:43 +02:00
jsonb.h Add const to values and nulls arguments 2023-10-10 07:50:43 +02:00
jsonfuncs.h Improve JsonLexContext's freeability 2023-10-05 10:59:08 +02:00
jsonpath.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
logtape.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
lsyscache.h Allow the use of a hash index on the subscriber during replication. 2023-07-14 08:21:54 +05:30
memdebug.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
memutils.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
memutils_internal.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
memutils_memorychunk.h Fix various typos 2023-04-18 13:23:23 +12:00
meson.build Add system view pg_wait_events 2023-08-20 15:35:02 +09:00
multirangetypes.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
numeric.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
palloc.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
partcache.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_crc.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_locale.h All supported systems have locale_t. 2023-07-09 11:55:18 +12:00
pg_lsn.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_rusage.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgstat_internal.h Fix various typos and incorrect/outdated name references 2023-04-19 13:50:33 +12:00
pidfile.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
plancache.h Rename OverrideSearchPath to SearchPathMatcher. 2023-07-31 17:04:47 -07:00
portal.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
ps_status.h Speedup and increase usability of set proc title functions 2023-02-20 16:18:27 +13:00
queryenvironment.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
rangetypes.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
regproc.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
rel.h Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
relcache.h Remove RelationGetIndexRawAttOptions() 2023-10-03 17:51:02 +02:00
relfilenumbermap.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
relmapper.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
relptr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
reltrigger.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
resowner.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
resowner_private.h bufmgr: Support multiple in-progress IOs by using resowner 2023-04-05 14:17:55 -07:00
rls.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
ruleutils.h pageinspect: Fix gist_page_items() with included columns 2023-05-19 12:37:58 +09:00
sampling.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
selfuncs.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
sharedtuplestore.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
snapmgr.h Remove the "snapshot too old" feature. 2023-09-05 19:53:43 +12:00
snapshot.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
sortsupport.h Fix various typos and incorrect/outdated name references 2023-04-19 13:50:33 +12:00
spccache.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
syscache.h Add SysCacheGetAttrNotNull for guaranteed not-null attrs 2023-03-25 22:49:33 +01:00
timeout.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
timestamp.h Add back SQLValueFunction for SQL keywords 2023-05-17 10:19:17 +09:00
tuplesort.h Add const to values and nulls arguments 2023-10-10 07:50:43 +02:00
tuplestore.h Add const to values and nulls arguments 2023-10-10 07:50:43 +02:00
typcache.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tzparser.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
usercontext.h Perform logical replication actions as the table owner. 2023-04-04 11:25:23 -04:00
uuid.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
varbit.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
varlena.h Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
wait_event.h Add system view pg_wait_events 2023-08-20 15:35:02 +09:00
xid8.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xml.h Support [NO] INDENT option in XMLSERIALIZE(). 2023-03-15 16:59:09 -04:00