Skip to content

Commit 6151769

Browse files
committed
Fix elog(FATAL) before PostmasterMain() or just after fork().
Since commit 97550c0, 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
1 parent 0fbcb9d commit 6151769

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/backend/main/main.c

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "bootstrap/bootstrap.h"
3535
#include "common/username.h"
36+
#include "miscadmin.h"
3637
#include "port/atomics.h"
3738
#include "postmaster/postmaster.h"
3839
#include "storage/s_lock.h"
@@ -96,6 +97,7 @@ main(int argc, char *argv[])
9697
* localization of messages may not work right away, and messages won't go
9798
* anywhere but stderr until GUC settings get loaded.
9899
*/
100+
MyProcPid = getpid();
99101
MemoryContextInit();
100102

101103
/*

src/backend/postmaster/fork_process.c

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <openssl/rand.h>
2121
#endif
2222

23+
#include "miscadmin.h"
2324
#include "postmaster/fork_process.h"
2425

2526
#ifndef WIN32
@@ -63,6 +64,7 @@ fork_process(void)
6364
if (result == 0)
6465
{
6566
/* fork succeeded, in child */
67+
MyProcPid = getpid();
6668
#ifdef LINUX_PROFILE
6769
setitimer(ITIMER_PROF, &prof_itimer, NULL);
6870
#endif

src/backend/postmaster/postmaster.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ ClosePostmasterPorts(bool am_syslogger)
26492649

26502650

26512651
/*
2652-
* InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds
2652+
* InitProcessGlobals -- set MyStartTime[stamp], random seeds
26532653
*
26542654
* Called early in the postmaster and every backend.
26552655
*/
@@ -2658,7 +2658,6 @@ InitProcessGlobals(void)
26582658
{
26592659
unsigned int rseed;
26602660

2661-
MyProcPid = getpid();
26622661
MyStartTimestamp = GetCurrentTimestamp();
26632662
MyStartTime = timestamptz_to_time_t(MyStartTimestamp);
26642663

0 commit comments

Comments
 (0)