Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8b9cbf4

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 939b090 commit 8b9cbf4

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/backend/main/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "bootstrap/bootstrap.h"
3434
#include "common/username.h"
35+
#include "miscadmin.h"
3536
#include "postmaster/postmaster.h"
3637
#include "tcop/tcopprot.h"
3738
#include "utils/help_config.h"
@@ -109,6 +110,7 @@ main(int argc, char *argv[])
109110
* localization of messages may not work right away, and messages won't go
110111
* anywhere but stderr until GUC settings get loaded.
111112
*/
113+
MyProcPid = getpid();
112114
MemoryContextInit();
113115

114116
/*

src/backend/postmaster/fork_process.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <unistd.h>
2020

2121
#include "libpq/pqsignal.h"
22+
#include "miscadmin.h"
2223
#include "postmaster/fork_process.h"
2324

2425
#ifndef WIN32
@@ -66,6 +67,7 @@ fork_process(void)
6667
if (result == 0)
6768
{
6869
/* fork succeeded, in child */
70+
MyProcPid = getpid();
6971
#ifdef LINUX_PROFILE
7072
setitimer(ITIMER_PROF, &prof_itimer, NULL);
7173
#endif

src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,14 +1899,13 @@ ClosePostmasterPorts(bool am_syslogger)
18991899

19001900

19011901
/*
1902-
* InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds
1902+
* InitProcessGlobals -- set MyStartTime[stamp], random seeds
19031903
*
19041904
* Called early in the postmaster and every backend.
19051905
*/
19061906
void
19071907
InitProcessGlobals(void)
19081908
{
1909-
MyProcPid = getpid();
19101909
MyStartTimestamp = GetCurrentTimestamp();
19111910
MyStartTime = timestamptz_to_time_t(MyStartTimestamp);
19121911

src/port/pqsignal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ static volatile pqsigfunc pqsignal_handlers[PG_NSIG];
7474
/*
7575
* Except when called with SIG_IGN or SIG_DFL, pqsignal() sets up this function
7676
* as the handler for all signals. This wrapper handler function checks that
77-
* it is called within a process that the server knows about (i.e., any process
78-
* that has called InitProcessGlobals(), such as a client backend), and not a
77+
* it is called within a process that knew to maintain MyProcPid, and not a
7978
* child process forked by system(3), etc. This check ensures that such child
8079
* processes do not modify shared memory, which is often detrimental. If the
8180
* check succeeds, the function originally provided to pqsignal() is called.

0 commit comments

Comments
 (0)