diff options
author | Noah Misch <noah@leadboat.com> | 2024-12-10 13:51:59 -0800 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2024-12-10 13:52:02 -0800 |
commit | 4bd9de3f4190242d3dbc3ddb2b1a5f87027efdd0 (patch) | |
tree | fb63cacd9675613eb6cd2f3e1afda6ee7bb3d13a /src/backend | |
parent | 67ef403d0e8f069368612adb917e42cd62cc6377 (diff) | |
download | postgresql-4bd9de3f4190242d3dbc3ddb2b1a5f87027efdd0.tar.gz postgresql-4bd9de3f4190242d3dbc3ddb2b1a5f87027efdd0.zip |
Fix elog(FATAL) before PostmasterMain() or just after fork().
Since commit 97550c0711972a9856b5db751539bbaf2f88884c, these failed with
"PANIC: proc_exit() called in child process" due to uninitialized or
stale MyProcPid. That was reachable if close() failed in
ClosePostmasterPorts() or setlocale(category, "C") failed, both
unlikely. Back-patch to v13 (all supported versions).
Discussion: https://postgr.es/m/20241208034614.45.nmisch@google.com
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/main/main.c | 2 | ||||
-rw-r--r-- | src/backend/postmaster/fork_process.c | 2 | ||||
-rw-r--r-- | src/backend/postmaster/postmaster.c | 3 |
3 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 4672aab8378..f14fb7c2aab 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -32,6 +32,7 @@ #include "bootstrap/bootstrap.h" #include "common/username.h" +#include "miscadmin.h" #include "port/atomics.h" #include "postmaster/postmaster.h" #include "tcop/tcopprot.h" @@ -96,6 +97,7 @@ main(int argc, char *argv[]) * localization of messages may not work right away, and messages won't go * anywhere but stderr until GUC settings get loaded. */ + MyProcPid = getpid(); MemoryContextInit(); /* diff --git a/src/backend/postmaster/fork_process.c b/src/backend/postmaster/fork_process.c index 5e42a74ab5f..b3010e3e36a 100644 --- a/src/backend/postmaster/fork_process.c +++ b/src/backend/postmaster/fork_process.c @@ -19,6 +19,7 @@ #include <unistd.h> #include "libpq/pqsignal.h" +#include "miscadmin.h" #include "postmaster/fork_process.h" #ifndef WIN32 @@ -66,6 +67,7 @@ fork_process(void) if (result == 0) { /* fork succeeded, in child */ + MyProcPid = getpid(); #ifdef LINUX_PROFILE setitimer(ITIMER_PROF, &prof_itimer, NULL); #endif diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index bf0241aed0c..30d0b57e577 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -2024,14 +2024,13 @@ ClosePostmasterPorts(bool am_syslogger) /* - * InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds + * InitProcessGlobals -- set MyStartTime[stamp], random seeds * * Called early in the postmaster and every backend. */ void InitProcessGlobals(void) { - MyProcPid = getpid(); MyStartTimestamp = GetCurrentTimestamp(); MyStartTime = timestamptz_to_time_t(MyStartTimestamp); |