Hi,
The behaviour you describe is expected and is the same with earlier version
of NT.
When the service is reporting status to the Service Control Manager, it as
to mention that it want to handle the shutdown event by specifying
SERVICE_ACCEPT_SHUTDOWN to the dwControlsAccepted member of SERVICE_STATUS
in a call to SetServiceStatus and then handle the SERVICE_CONTROL_SHUTDOWN
event in the handler for ServiceControl.
This should solve the problem:
change in service.c:
BOOL ReportStatusToSCMgr(DWORD dwCurrentState,
DWORD dwWin32ExitCode,
DWORD dwWaitHint)
{
static DWORD dwCheckPoint = 1;
BOOL fResult = TRUE;
if ( !bDebug ) // when debugging we don't report to the SCM
{
if (dwCurrentState == SERVICE_START_PENDING)
ssStatus.dwControlsAccepted = 0;
else
// Change here
// ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP |
SERVICE_ACCEPT_SHUTDOWN;
// ....
// The rest is the same
}
AND
VOID WINAPI service_ctrl(DWORD dwCtrlCode)
{
// Handle the requested control code.
//
switch(dwCtrlCode)
{
// Stop the service.
//
// The folowing line is added
// Note: Only the system can send SERVICE_CONTROL_SHUTDOWN to
// a service, otherwise the function ControlService will fail.
// USE WITH CAUTION see note at the end.
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
ssStatus.dwCurrentState = SERVICE_STOP_PENDING;
ServiceStop();
break;
// ....
// The rest is the same
}
David Campeau,
P.S: I sent a similar message to George Woltman about a month ago, but I
didn't receive any response. Perhaps there is something else I am
overlooking?
NOTE (taken from MSDN):
The SERVICE_CONTROL_SHUTDOWN control should only be processed by services
that must absolutely clean up during shutdown, because there is an extremely
limited time (about 20 seconds) available for service shutdown. After this
time expires, system shutdown proceeds regardless of whether service
shutdown is complete. If the service needs to take more time to shut down,
it should send out STOP_PENDING status messages, along with a wait hint, so
that the service controller knows how long to wait before reporting to the
system that service shutdown is complete. For example, the server service
needs to shut down so that network connections are not made when the system
is in the shutdown state.
_________________________________________________________________
Unsubscribe & list info -- http://www.scruz.net/~luke/signup.htm
Mersenne Prime FAQ -- http://www.tasam.com/~lrwiman/FAQ-mers