/*
* Forward declarations
*/
-void uninit_io_completion_port();
-int ntpdmain(int argc, char *argv[]);
-void WINAPI ServiceControl(DWORD dwCtrlCode);
-void ntservice_exit(void);
+extern void uninit_io_completion_port();
+extern int ntpdmain(int argc, char *argv[]);
+extern void WINAPI ServiceControl(DWORD dwCtrlCode);
+extern void ntservice_exit(void);
#ifdef WRAP_DBG_MALLOC
void *wrap_dbg_malloc(size_t s, const char *f, int l);
* Initialize the Service by registering it.
*/
void
-ntservice_init() {
+ntservice_init(void)
+{
char ConsoleTitle[256];
if (!foreground) {
ServiceControl);
if (!hServiceStatus) {
NTReportError(NTP_SERVICE_NAME,
- "could not register service control handler");
+ "could not register with SCM");
exit(1);
}
- UpdateSCM(SERVICE_RUNNING);
+ UpdateSCM(SERVICE_START_PENDING);
} else {
snprintf(ConsoleTitle, sizeof(ConsoleTitle),
"NTP Version %s", Version);
atexit( ntservice_exit );
}
+void
+ntservice_isup(void)
+{
+ if (!foreground) {
+ /* Register handler with the SCM */
+ if (!hServiceStatus) {
+ NTReportError(NTP_SERVICE_NAME,
+ "could not report to SCM");
+ exit(1);
+ }
+ UpdateSCM(SERVICE_RUNNING);
+ }
+}
/*
* Routine to check if the service is stopping
* because the computer is shutting down
*/
BOOL
-ntservice_systemisshuttingdown() {
+ntservice_systemisshuttingdown(void)
+{
return computer_shutting_down;
}
void
-ntservice_exit( void )
+ntservice_exit(void)
{
uninit_io_completion_port();
Sleep( 200 ); //##++
/*
* Tell the Service Control Manager the state of the service.
*/
-void UpdateSCM(DWORD state) {
- SERVICE_STATUS ss;
+void
+UpdateSCM(
+ DWORD state
+ )
+{
static DWORD dwState = SERVICE_STOPPED;
+ static DWORD dwCheck = 0;
+
+ SERVICE_STATUS ss;
if (hServiceStatus) {
if (state)
ZERO(ss);
ss.dwServiceType |= SERVICE_WIN32_OWN_PROCESS;
ss.dwCurrentState = dwState;
- ss.dwControlsAccepted = SERVICE_ACCEPT_STOP |
- SERVICE_ACCEPT_SHUTDOWN;
- ss.dwCheckPoint = 0;
- ss.dwServiceSpecificExitCode = 0;
- ss.dwWin32ExitCode = NO_ERROR;
- ss.dwWaitHint = dwState == SERVICE_STOP_PENDING ? 5000 : 1000;
+ /* ss.dwServiceSpecificExitCode = 0; default by ZERO(ss) */
+ /* ss.dwWin32ExitCode = NO_ERROR; default by ZERO(ss) */
+
+ switch (dwState) {
+ case SERVICE_START_PENDING:
+ ss.dwControlsAccepted = 0;
+ ss.dwWaitHint = 15000;
+ ss.dwCheckPoint = ++dwCheck;
+ break;
+ case SERVICE_STOP_PENDING:
+ ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+ ss.dwWaitHint = 3000;
+ ss.dwCheckPoint = ++dwCheck;
+ break;
+ default:
+ ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+ ss.dwWaitHint = 1000;
+ ss.dwCheckPoint = dwCheck = 0;
+ break;
+ }
SetServiceStatus(hServiceStatus, &ss);
}