Correct behavior with passing back errors on onStart, onStop.

This commit is contained in:
Daniel Theophanes
2012-03-08 16:45:31 -08:00
parent 9c12e059b5
commit ad4beb2a49
2 changed files with 166 additions and 161 deletions
+3
View File
@@ -15,6 +15,9 @@ type Service interface {
// Call quickly after initial entry point. Does not return until // Call quickly after initial entry point. Does not return until
// service is ready to stop. onStart is called when the service is // service is ready to stop. onStart is called when the service is
// starting, returning an error will fail to start the service. // starting, returning an error will fail to start the service.
// If an error is returned from onStop, the service will still stop.
// An error passed from onStart or onStop will be returned as
// an error from Run.
// Both callbacks should return quickly and not block. // Both callbacks should return quickly and not block.
Run(onStart, onStop func() error) error Run(onStart, onStop func() error) error
+3 -1
View File
@@ -97,6 +97,7 @@ VOID WINAPI SvcMain( DWORD dwArgc, LPTSTR *lpszArgv )
goSigStart = 1; goSigStart = 1;
WaitForSingleObject(goWaitStart, INFINITE); WaitForSingleObject(goWaitStart, INFINITE);
if(goAckStart != 1) { if(goAckStart != 1) {
ReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
return; return;
} }
@@ -171,6 +172,7 @@ VOID WINAPI SvcCtrlHandler( DWORD dwCtrl ) {
goSigStop = 1; goSigStop = 1;
WaitForSingleObject(goWaitStop, INFINITE); WaitForSingleObject(goWaitStop, INFINITE);
if(goAckStop != 1) { if(goAckStop != 1) {
ReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
return; return;
} }
@@ -222,7 +224,7 @@ func runService(serviceName string, onStart, onStop func() error) error {
err := onStop() err := onStop()
if err != nil { if err != nil {
// An error was returned. // An error was returned.
// Signal to NOT stop the service. // Will signal to stop service.
C.continueStop(-1) C.continueStop(-1)
retErr <- err retErr <- err
return return