Re: Building Postgresql under Windows question - Mailing list pgsql-hackers
| From | Dann Corbit |
|---|---|
| Subject | Re: Building Postgresql under Windows question |
| Date | |
| Msg-id | D425483C2C5C9F49B5B7A41F8944154702962197@postal.corporate.connx.com Whole thread Raw |
| In response to | Re: Building Postgresql under Windows question (Andrew Dunstan <andrew@dunslane.net>) |
| Responses |
Re: Building Postgresql under Windows question
|
| List | pgsql-hackers |
> -----Original Message-----
> From: Andrew Dunstan [mailto:andrew@dunslane.net]
> Sent: Tuesday, April 28, 2009 12:42 PM
> To: Dann Corbit
> Cc: pgsql-hackers@postgresql.org
> Subject: Re: [HACKERS] Building Postgresql under Windows question
>
>
>
> Dann Corbit wrote:
> > Pg_ctl.exe is exiting with a success code from line 1946 of PG_CTL.C
> >
> > This is not appropriate behavior for a service unless shutdown has
> been
> > requested.
> >
>
> pg_ctl calls *StartServiceCtrlDispatcher*(). It can only get to the
> line
> you mention when called as a service after that call returns. MSDN
> states:
>
> "If *StartServiceCtrlDispatcher* succeeds, it connects the calling
> thread to the service control manager and does not return until all
> running services in the process have entered the SERVICE_STOPPED
> state."
>
> So it appears that something is causing your service to enter that
> state.
It appears that SERVICE_STOPPED comes from here:
static void WINAPI
pgwin32_ServiceMain(DWORD argc, LPTSTR * argv)
{PROCESS_INFORMATION pi;DWORD ret;DWORD check_point_start;
/* Initialize variables */status.dwWin32ExitCode = S_OK;status.dwCheckPoint = 0;status.dwWaitHint =
60000;status.dwServiceType= SERVICE_WIN32_OWN_PROCESS;status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_PAUSE_CONTINUE;status.dwServiceSpecificExitCode = 0;status.dwCurrentState =
SERVICE_START_PENDING;
memset(&pi, 0, sizeof(pi));
read_post_opts();
/* Register the control request handler */if ((hStatus = RegisterServiceCtrlHandler(register_servicename,
pgwin32_ServiceHandler)) == (SERVICE_STATUS_HANDLE) 0) return;
if ((shutdownEvent = CreateEvent(NULL, true, false, NULL)) ==
NULL) return;
/* Start the postmaster */pgwin32_SetServiceStatus(SERVICE_START_PENDING);if
(!CreateRestrictedProcess(pgwin32_CommandLine(false),&pi,
true)){ pgwin32_SetServiceStatus(SERVICE_STOPPED); return;}postmasterPID = pi.dwProcessId;postmasterProcess =
pi.hProcess;CloseHandle(pi.hThread);
if (do_wait){ write_eventlog(EVENTLOG_INFORMATION_TYPE, _("Waiting for
server startup...\n")); if (test_postmaster_connection(true) == false) {
write_eventlog(EVENTLOG_INFORMATION_TYPE,
_("Timed out waiting for server startup\n")); pgwin32_SetServiceStatus(SERVICE_STOPPED); return; }
write_eventlog(EVENTLOG_INFORMATION_TYPE,_("Server
started and accepting connections\n"));}
/* * Save the checkpoint value as it might have been incremented
in * test_postmaster_connection */check_point_start = status.dwCheckPoint;
pgwin32_SetServiceStatus(SERVICE_RUNNING);
/* Wait for quit... */ret = WaitForMultipleObjects(2, shutdownHandles, FALSE,
INFINITE);
pgwin32_SetServiceStatus(SERVICE_STOP_PENDING);switch (ret){ case WAIT_OBJECT_0: /* shutdown event */
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 < 12) status.dwCheckPoint++; break;
case (WAIT_OBJECT_0 + 1): /* postmaster
went down */ break;
default: /* shouldn't get here? */ break;}
CloseHandle(shutdownEvent);CloseHandle(postmasterProcess);
pgwin32_SetServiceStatus(SERVICE_STOPPED);
}
I will set a breakpoint on every place that the status is set to
SERVICE_STOPPED and report what I have found.
pgsql-hackers by date: