Skip to content

Commit 4000170

Browse files
committed
Avoid terminating the postmaster on a number of "can't happen" cases during
backend startup on Win32. Instead, log the error and just forget about the potentially dangling process, since we can't do anything about it anyway.
1 parent 6403c35 commit 4000170

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.585 2009/07/24 20:12:42 mha Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.586 2009/08/06 09:50:22 mha Exp $
4141
*
4242
* NOTES
4343
*
@@ -3627,7 +3627,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
36273627
* mess with the half-started process
36283628
*/
36293629
if (!TerminateProcess(pi.hProcess, 255))
3630-
ereport(ERROR,
3630+
ereport(LOG,
36313631
(errmsg_internal("could not terminate unstarted process: error code %d",
36323632
(int) GetLastError())));
36333633
CloseHandle(pi.hProcess);
@@ -3654,7 +3654,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
36543654
* process and give up.
36553655
*/
36563656
if (!TerminateProcess(pi.hProcess, 255))
3657-
ereport(ERROR,
3657+
ereport(LOG,
36583658
(errmsg_internal("could not terminate process that failed to reserve memory: error code %d",
36593659
(int) GetLastError())));
36603660
CloseHandle(pi.hProcess);
@@ -3671,7 +3671,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
36713671
{
36723672
if (!TerminateProcess(pi.hProcess, 255))
36733673
{
3674-
ereport(ERROR,
3674+
ereport(LOG,
36753675
(errmsg_internal("could not terminate unstartable process: error code %d",
36763676
(int) GetLastError())));
36773677
CloseHandle(pi.hProcess);
@@ -3680,7 +3680,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
36803680
}
36813681
CloseHandle(pi.hProcess);
36823682
CloseHandle(pi.hThread);
3683-
ereport(ERROR,
3683+
ereport(LOG,
36843684
(errmsg_internal("could not resume thread of unstarted process: error code %d",
36853685
(int) GetLastError())));
36863686
return -1;
@@ -4430,8 +4430,8 @@ extern int pgStatSock;
44304430
#define write_inheritable_socket(dest, src, childpid) (*(dest) = (src))
44314431
#define read_inheritable_socket(dest, src) (*(dest) = *(src))
44324432
#else
4433-
static void write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE child);
4434-
static void write_inheritable_socket(InheritableSocket *dest, SOCKET src,
4433+
static bool write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE child);
4434+
static bool write_inheritable_socket(InheritableSocket *dest, SOCKET src,
44354435
pid_t childPid);
44364436
static void read_inheritable_socket(SOCKET *dest, InheritableSocket *src);
44374437
#endif
@@ -4448,7 +4448,8 @@ save_backend_variables(BackendParameters *param, Port *port,
44484448
#endif
44494449
{
44504450
memcpy(&param->port, port, sizeof(Port));
4451-
write_inheritable_socket(&param->portsocket, port->sock, childPid);
4451+
if (!write_inheritable_socket(&param->portsocket, port->sock, childPid))
4452+
return false;
44524453

44534454
strlcpy(param->DataDir, DataDir, MAXPGPATH);
44544455

@@ -4469,7 +4470,8 @@ save_backend_variables(BackendParameters *param, Port *port,
44694470
param->ProcGlobal = ProcGlobal;
44704471
param->AuxiliaryProcs = AuxiliaryProcs;
44714472
param->PMSignalState = PMSignalState;
4472-
write_inheritable_socket(&param->pgStatSock, pgStatSock, childPid);
4473+
if (!write_inheritable_socket(&param->pgStatSock, pgStatSock, childPid))
4474+
return false;
44734475

44744476
param->PostmasterPid = PostmasterPid;
44754477
param->PgStartTime = PgStartTime;
@@ -4479,9 +4481,10 @@ save_backend_variables(BackendParameters *param, Port *port,
44794481

44804482
#ifdef WIN32
44814483
param->PostmasterHandle = PostmasterHandle;
4482-
write_duplicated_handle(&param->initial_signal_pipe,
4484+
if (!write_duplicated_handle(&param->initial_signal_pipe,
44834485
pgwin32_create_signal_listener(childPid),
4484-
childProcess);
4486+
childProcess))
4487+
return false;
44854488
#endif
44864489

44874490
memcpy(&param->syslogPipe, &syslogPipe, sizeof(syslogPipe));
@@ -4501,7 +4504,7 @@ save_backend_variables(BackendParameters *param, Port *port,
45014504
* Duplicate a handle for usage in a child process, and write the child
45024505
* process instance of the handle to the parameter file.
45034506
*/
4504-
static void
4507+
static bool
45054508
write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE childProcess)
45064509
{
45074510
HANDLE hChild = INVALID_HANDLE_VALUE;
@@ -4513,11 +4516,15 @@ write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE childProcess)
45134516
0,
45144517
TRUE,
45154518
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
4516-
ereport(ERROR,
4519+
{
4520+
ereport(LOG,
45174521
(errmsg_internal("could not duplicate handle to be written to backend parameter file: error code %d",
45184522
(int) GetLastError())));
4523+
return false;
4524+
}
45194525

45204526
*dest = hChild;
4527+
return true;
45214528
}
45224529

45234530
/*
@@ -4527,18 +4534,22 @@ write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE childProcess)
45274534
* common on Windows (antivirus, firewalls, download managers etc) break
45284535
* straight socket inheritance.
45294536
*/
4530-
static void
4537+
static bool
45314538
write_inheritable_socket(InheritableSocket *dest, SOCKET src, pid_t childpid)
45324539
{
45334540
dest->origsocket = src;
45344541
if (src != 0 && src != -1)
45354542
{
45364543
/* Actual socket */
45374544
if (WSADuplicateSocket(src, childpid, &dest->wsainfo) != 0)
4538-
ereport(ERROR,
4545+
{
4546+
ereport(LOG,
45394547
(errmsg("could not duplicate socket %d for use in backend: error code %d",
45404548
src, WSAGetLastError())));
4549+
return false;
4550+
}
45414551
}
4552+
return true;
45424553
}
45434554

45444555
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy