Skip to content

Commit c6719a2

Browse files
committed
Implement new PostmasterIsAlive() check for WIN32, per Claudio Natoli.
In passing, align a few error messages with the style guide.
1 parent 076a055 commit c6719a2

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 37 additions & 14 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.400 2004/05/29 22:48:19 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.401 2004/05/30 03:50:11 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -276,6 +276,8 @@ static DWORD WINAPI win32_sigchld_waiter(LPVOID param);
276276
static pid_t *win32_childPIDArray;
277277
static HANDLE *win32_childHNDArray;
278278
static unsigned long win32_numChildren = 0;
279+
280+
HANDLE PostmasterHandle;
279281
#endif
280282

281283
static pid_t backend_forkexec(Port *port);
@@ -748,6 +750,21 @@ PostmasterMain(int argc, char *argv[])
748750
ereport(FATAL,
749751
(errcode(ERRCODE_OUT_OF_MEMORY),
750752
errmsg("out of memory")));
753+
754+
/*
755+
* Set up a handle that child processes can use to check whether the
756+
* postmaster is still running.
757+
*/
758+
if (DuplicateHandle(GetCurrentProcess(),
759+
GetCurrentProcess(),
760+
GetCurrentProcess(),
761+
&PostmasterHandle,
762+
0,
763+
TRUE,
764+
DUPLICATE_SAME_ACCESS) == 0)
765+
ereport(FATAL,
766+
(errmsg_internal("could not duplicate postmaster handle: %d",
767+
(int) GetLastError())));
751768
#endif
752769

753770
/*
@@ -3221,6 +3238,9 @@ write_backend_variables(char *filename, Port *port)
32213238

32223239
write_var(debug_flag, fp);
32233240
write_var(PostmasterPid, fp);
3241+
#ifdef WIN32
3242+
write_var(PostmasterHandle, fp);
3243+
#endif
32243244

32253245
StrNCpy(str_buf, my_exec_path, MAXPGPATH);
32263246
write_array_var(str_buf, fp);
@@ -3289,6 +3309,9 @@ read_backend_variables(char *filename, Port *port)
32893309

32903310
read_var(debug_flag, fp);
32913311
read_var(PostmasterPid, fp);
3312+
#ifdef WIN32
3313+
read_var(PostmasterHandle, fp);
3314+
#endif
32923315

32933316
read_array_var(str_buf, fp);
32943317
StrNCpy(my_exec_path, str_buf, MAXPGPATH);
@@ -3360,7 +3383,7 @@ ShmemBackendArrayRemove(pid_t pid)
33603383
}
33613384

33623385
ereport(WARNING,
3363-
(errmsg_internal("unable to find backend entry with pid %d",
3386+
(errmsg_internal("could not find backend entry with pid %d",
33643387
(int) pid)));
33653388
}
33663389

@@ -3411,22 +3434,22 @@ win32_forkexec(const char *path, char *argv[])
34113434
win32_AddChild(pi.dwProcessId, pi.hProcess);
34123435
}
34133436

3414-
if (!DuplicateHandle(GetCurrentProcess(),
3415-
pi.hProcess,
3416-
GetCurrentProcess(),
3417-
&childHandleCopy,
3418-
0,
3419-
FALSE,
3420-
DUPLICATE_SAME_ACCESS))
3437+
if (DuplicateHandle(GetCurrentProcess(),
3438+
pi.hProcess,
3439+
GetCurrentProcess(),
3440+
&childHandleCopy,
3441+
0,
3442+
FALSE,
3443+
DUPLICATE_SAME_ACCESS) == 0)
34213444
ereport(FATAL,
3422-
(errmsg_internal("failed to duplicate child handle: %d",
3445+
(errmsg_internal("could not duplicate child handle: %d",
34233446
(int) GetLastError())));
34243447

34253448
waiterThread = CreateThread(NULL, 64 * 1024, win32_sigchld_waiter,
34263449
(LPVOID) childHandleCopy, 0, NULL);
34273450
if (!waiterThread)
34283451
ereport(FATAL,
3429-
(errmsg_internal("failed to create sigchld waiter thread: %d",
3452+
(errmsg_internal("could not create sigchld waiter thread: %d",
34303453
(int) GetLastError())));
34313454
CloseHandle(waiterThread);
34323455

@@ -3460,7 +3483,7 @@ win32_AddChild(pid_t pid, HANDLE handle)
34603483
}
34613484
else
34623485
ereport(FATAL,
3463-
(errmsg_internal("unable to add child entry with pid %lu",
3486+
(errmsg_internal("no room for child entry with pid %lu",
34643487
(unsigned long) pid)));
34653488
}
34663489

@@ -3486,7 +3509,7 @@ win32_RemoveChild(pid_t pid)
34863509
}
34873510

34883511
ereport(WARNING,
3489-
(errmsg_internal("unable to find child entry with pid %lu",
3512+
(errmsg_internal("could not find child entry with pid %lu",
34903513
(unsigned long) pid)));
34913514
}
34923515

@@ -3562,7 +3585,7 @@ win32_sigchld_waiter(LPVOID param)
35623585
if (r == WAIT_OBJECT_0)
35633586
pg_queue_signal(SIGCHLD);
35643587
else
3565-
fprintf(stderr, "ERROR: Failed to wait on child process handle: %i\n",
3588+
fprintf(stderr, "ERROR: failed to wait on child process handle: %d\n",
35663589
(int) GetLastError());
35673590
CloseHandle(procHandle);
35683591
return 0;

src/backend/storage/ipc/pmsignal.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.14 2004/05/29 22:48:20 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.15 2004/05/30 03:50:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -18,6 +18,7 @@
1818
#include <unistd.h>
1919

2020
#include "miscadmin.h"
21+
#include "postmaster/postmaster.h"
2122
#include "storage/pmsignal.h"
2223
#include "storage/shmem.h"
2324

@@ -115,9 +116,6 @@ PostmasterIsAlive(bool amDirectChild)
115116
return (kill(PostmasterPid, 0) == 0);
116117
}
117118
#else /* WIN32 */
118-
/*
119-
* XXX needs to be implemented by somebody
120-
*/
121-
return true;
119+
return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT);
122120
#endif /* WIN32 */
123121
}

src/include/postmaster/postmaster.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.1 2004/05/29 22:48:23 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.2 2004/05/30 03:50:15 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -30,6 +30,10 @@ extern bool Log_connections;
3030
extern bool log_hostname;
3131
extern char *rendezvous_name;
3232

33+
#ifdef WIN32
34+
extern HANDLE PostmasterHandle;
35+
#endif
36+
3337

3438
extern int PostmasterMain(int argc, char *argv[]);
3539
extern void ClosePostmasterPorts(void);

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