]> granicus.if.org Git - postgresql/commitdiff
Properly send SCM status updates when shutting down service on Windows
authorMagnus Hagander <magnus@hagander.net>
Thu, 7 May 2015 13:04:13 +0000 (15:04 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 7 May 2015 13:09:21 +0000 (15:09 +0200)
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

src/bin/pg_ctl/pg_ctl.c

index 91e99e4c20965b6e12af86eae3f8402834732983..f767f2e697b46e607f822f3477157a13ddeea16f 100644 (file)
@@ -1590,15 +1590,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;