Commit c6719a27 authored by Tom Lane's avatar Tom Lane

Implement new PostmasterIsAlive() check for WIN32, per Claudio Natoli.

In passing, align a few error messages with the style guide.
parent 076a055a
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.400 2004/05/29 22:48:19 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.401 2004/05/30 03:50:11 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -276,6 +276,8 @@ static DWORD WINAPI win32_sigchld_waiter(LPVOID param); ...@@ -276,6 +276,8 @@ static DWORD WINAPI win32_sigchld_waiter(LPVOID param);
static pid_t *win32_childPIDArray; static pid_t *win32_childPIDArray;
static HANDLE *win32_childHNDArray; static HANDLE *win32_childHNDArray;
static unsigned long win32_numChildren = 0; static unsigned long win32_numChildren = 0;
HANDLE PostmasterHandle;
#endif #endif
static pid_t backend_forkexec(Port *port); static pid_t backend_forkexec(Port *port);
...@@ -748,6 +750,21 @@ PostmasterMain(int argc, char *argv[]) ...@@ -748,6 +750,21 @@ PostmasterMain(int argc, char *argv[])
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"))); errmsg("out of memory")));
/*
* Set up a handle that child processes can use to check whether the
* postmaster is still running.
*/
if (DuplicateHandle(GetCurrentProcess(),
GetCurrentProcess(),
GetCurrentProcess(),
&PostmasterHandle,
0,
TRUE,
DUPLICATE_SAME_ACCESS) == 0)
ereport(FATAL,
(errmsg_internal("could not duplicate postmaster handle: %d",
(int) GetLastError())));
#endif #endif
/* /*
...@@ -3221,6 +3238,9 @@ write_backend_variables(char *filename, Port *port) ...@@ -3221,6 +3238,9 @@ write_backend_variables(char *filename, Port *port)
write_var(debug_flag, fp); write_var(debug_flag, fp);
write_var(PostmasterPid, fp); write_var(PostmasterPid, fp);
#ifdef WIN32
write_var(PostmasterHandle, fp);
#endif
StrNCpy(str_buf, my_exec_path, MAXPGPATH); StrNCpy(str_buf, my_exec_path, MAXPGPATH);
write_array_var(str_buf, fp); write_array_var(str_buf, fp);
...@@ -3289,6 +3309,9 @@ read_backend_variables(char *filename, Port *port) ...@@ -3289,6 +3309,9 @@ read_backend_variables(char *filename, Port *port)
read_var(debug_flag, fp); read_var(debug_flag, fp);
read_var(PostmasterPid, fp); read_var(PostmasterPid, fp);
#ifdef WIN32
read_var(PostmasterHandle, fp);
#endif
read_array_var(str_buf, fp); read_array_var(str_buf, fp);
StrNCpy(my_exec_path, str_buf, MAXPGPATH); StrNCpy(my_exec_path, str_buf, MAXPGPATH);
...@@ -3360,7 +3383,7 @@ ShmemBackendArrayRemove(pid_t pid) ...@@ -3360,7 +3383,7 @@ ShmemBackendArrayRemove(pid_t pid)
} }
ereport(WARNING, ereport(WARNING,
(errmsg_internal("unable to find backend entry with pid %d", (errmsg_internal("could not find backend entry with pid %d",
(int) pid))); (int) pid)));
} }
...@@ -3411,22 +3434,22 @@ win32_forkexec(const char *path, char *argv[]) ...@@ -3411,22 +3434,22 @@ win32_forkexec(const char *path, char *argv[])
win32_AddChild(pi.dwProcessId, pi.hProcess); win32_AddChild(pi.dwProcessId, pi.hProcess);
} }
if (!DuplicateHandle(GetCurrentProcess(), if (DuplicateHandle(GetCurrentProcess(),
pi.hProcess, pi.hProcess,
GetCurrentProcess(), GetCurrentProcess(),
&childHandleCopy, &childHandleCopy,
0, 0,
FALSE, FALSE,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS) == 0)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("failed to duplicate child handle: %d", (errmsg_internal("could not duplicate child handle: %d",
(int) GetLastError()))); (int) GetLastError())));
waiterThread = CreateThread(NULL, 64 * 1024, win32_sigchld_waiter, waiterThread = CreateThread(NULL, 64 * 1024, win32_sigchld_waiter,
(LPVOID) childHandleCopy, 0, NULL); (LPVOID) childHandleCopy, 0, NULL);
if (!waiterThread) if (!waiterThread)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("failed to create sigchld waiter thread: %d", (errmsg_internal("could not create sigchld waiter thread: %d",
(int) GetLastError()))); (int) GetLastError())));
CloseHandle(waiterThread); CloseHandle(waiterThread);
...@@ -3460,7 +3483,7 @@ win32_AddChild(pid_t pid, HANDLE handle) ...@@ -3460,7 +3483,7 @@ win32_AddChild(pid_t pid, HANDLE handle)
} }
else else
ereport(FATAL, ereport(FATAL,
(errmsg_internal("unable to add child entry with pid %lu", (errmsg_internal("no room for child entry with pid %lu",
(unsigned long) pid))); (unsigned long) pid)));
} }
...@@ -3486,7 +3509,7 @@ win32_RemoveChild(pid_t pid) ...@@ -3486,7 +3509,7 @@ win32_RemoveChild(pid_t pid)
} }
ereport(WARNING, ereport(WARNING,
(errmsg_internal("unable to find child entry with pid %lu", (errmsg_internal("could not find child entry with pid %lu",
(unsigned long) pid))); (unsigned long) pid)));
} }
...@@ -3562,7 +3585,7 @@ win32_sigchld_waiter(LPVOID param) ...@@ -3562,7 +3585,7 @@ win32_sigchld_waiter(LPVOID param)
if (r == WAIT_OBJECT_0) if (r == WAIT_OBJECT_0)
pg_queue_signal(SIGCHLD); pg_queue_signal(SIGCHLD);
else else
fprintf(stderr, "ERROR: Failed to wait on child process handle: %i\n", fprintf(stderr, "ERROR: failed to wait on child process handle: %d\n",
(int) GetLastError()); (int) GetLastError());
CloseHandle(procHandle); CloseHandle(procHandle);
return 0; return 0;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.14 2004/05/29 22:48:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.15 2004/05/30 03:50:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <unistd.h> #include <unistd.h>
#include "miscadmin.h" #include "miscadmin.h"
#include "postmaster/postmaster.h"
#include "storage/pmsignal.h" #include "storage/pmsignal.h"
#include "storage/shmem.h" #include "storage/shmem.h"
...@@ -115,9 +116,6 @@ PostmasterIsAlive(bool amDirectChild) ...@@ -115,9 +116,6 @@ PostmasterIsAlive(bool amDirectChild)
return (kill(PostmasterPid, 0) == 0); return (kill(PostmasterPid, 0) == 0);
} }
#else /* WIN32 */ #else /* WIN32 */
/* return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT);
* XXX needs to be implemented by somebody
*/
return true;
#endif /* WIN32 */ #endif /* WIN32 */
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.1 2004/05/29 22:48:23 tgl Exp $ * $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.2 2004/05/30 03:50:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -30,6 +30,10 @@ extern bool Log_connections; ...@@ -30,6 +30,10 @@ extern bool Log_connections;
extern bool log_hostname; extern bool log_hostname;
extern char *rendezvous_name; extern char *rendezvous_name;
#ifdef WIN32
extern HANDLE PostmasterHandle;
#endif
extern int PostmasterMain(int argc, char *argv[]); extern int PostmasterMain(int argc, char *argv[]);
extern void ClosePostmasterPorts(void); extern void ClosePostmasterPorts(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment