summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2015-05-07 13:04:13 +0000
committerMagnus Hagander2015-05-07 13:10:01 +0000
commit78ce2dc8ee5dc393a2b2806bef922215e82d9db7 (patch)
treeda20de0f7dd26d7603aaa57e381d1dde8c098449
parentba7bee837ec1cee4809cdbaeba2104be37dee5dc (diff)
Properly send SCM status updates when shutting down service on Windows
The Service Control Manager should be notified regularly during a shutdown that takes a long time. Previously we would increaes the counter, but forgot to actually send the notification to the system. The loop counter was also incorrectly initalized in the event that the startup of the system took long enough for it to increase, which could cause the shutdown process not to wait as long as expected. Krystian Bigaj, reviewed by Michael Paquier
-rw-r--r--src/bin/pg_ctl/pg_ctl.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index adc55d22370..385fe34d865 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -1358,15 +1358,27 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
switch (ret)
{
case WAIT_OBJECT_0: /* shutdown event */
- kill(postmasterPID, SIGINT);
+ {
+ /*
+ * status.dwCheckPoint can be incremented by
+ * test_postmaster_connection(true), so it might not
+ * start from 0.
+ */
+ int maxShutdownCheckPoint = status.dwCheckPoint + 12;;
- /*
- * Increment the checkpoint and try again Abort after 12
- * checkpoints as the postmaster has probably hung
- */
- while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12)
- status.dwCheckPoint++;
- break;
+ kill(postmasterPID, SIGINT);
+
+ /*
+ * Increment the checkpoint and try again. Abort after 12
+ * checkpoints as the postmaster has probably hung.
+ */
+ while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint)
+ {
+ status.dwCheckPoint++;
+ SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
+ }
+ break;
+ }
case (WAIT_OBJECT_0 + 1): /* postmaster went down */
break;