Skip to content

Commit 315264d

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 4922ede commit 315264d

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/backend/main/main.c

Lines changed: 2 additions & 0 deletions
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/spin.h"
@@ -95,6 +96,7 @@ main(int argc, char *argv[])
9596
* localization of messages may not work right away, and messages won't go
9697
* anywhere but stderr until GUC settings get loaded.
9798
*/
99+
MyProcPid = getpid();
98100
MemoryContextInit();
99101

100102
/*

src/backend/postmaster/fork_process.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <sys/time.h>
1818
#include <unistd.h>
1919

20+
#include "miscadmin.h"
2021
#include "postmaster/fork_process.h"
2122

2223
#ifndef WIN32
@@ -60,6 +61,7 @@ fork_process(void)
6061
if (result == 0)
6162
{
6263
/* fork succeeded, in child */
64+
MyProcPid = getpid();
6365
#ifdef LINUX_PROFILE
6466
setitimer(ITIMER_PROF, &prof_itimer, NULL);
6567
#endif

src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@ ClosePostmasterPorts(bool am_syslogger)
26462646

26472647

26482648
/*
2649-
* InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds
2649+
* InitProcessGlobals -- set MyStartTime[stamp], random seeds
26502650
*
26512651
* Called early in the postmaster and every backend.
26522652
*/
@@ -2655,7 +2655,6 @@ InitProcessGlobals(void)
26552655
{
26562656
unsigned int rseed;
26572657

2658-
MyProcPid = getpid();
26592658
MyStartTimestamp = GetCurrentTimestamp();
26602659
MyStartTime = timestamptz_to_time_t(MyStartTimestamp);
26612660

0 commit comments

Comments
 (0)