cygrunsrv hangs forever on exec error (fix included)

Christian Franke Christian.Franke@t-online.de
Sat Nov 12 18:54:00 GMT 2005


Hi,

if the exec in cygrunsrv fails or the command exits to early, cygrunsrv 
will hang forever.
The service can no longer be controlled until cygrunsrv has been kill(-9)ed.
Auto restart of service does not work in this case.


Steps to reproduce (at least on XP SP2):

$ cygrunsrv -I test -p /bin/true

$ cygrunsrv -S test
cygrunsrv: Error starting a service: ... Win32 error 1053:
...

$ sleep 3600 #;-)

$ cygrunsrv -S test
Service             : test
Current State       : Start Pending
Controls Accepted   : Stop
Command             : /bin/true

cygrunsrv process has to be killed manually.

Same result occurs if the command's exe is removed.


This is due to the following (IMO undocumented and "interesting";-) 
behavior of the windows SCM:

The StartServiceControlDispatcher() routine does not return unless some 
thread (no necessarily service_main()) sets SERVICE_STOPPED.

The service_main() thread started by SCM is left alone.
Exiting service_main() does nothing, in particular it does not end 
StartServiceControlDispatcher().

But, if SERVICE_STOPPED is set, StartServiceControlDispatcher() 
immediately returns, again without any care about service_main().
Because usually now the program exit()'s and kills all threads, code 
following SERVICE_STOPPED may not be executed at all.


The attached patch for cygrunsrv-1.10.1 demonstrates this behavior via 
LOG_DEBUG messages.

With the _exit() at the end of service_main(), cygrunsrv does no longer 
hang and auto-restart of services works.

Note that the messages at the end of service_main() will never be 
written if a service exits normally
(Try with: cygrunsrv -I ... -p /bin/sleep -a 30)

Thanks for any comment

Christian


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygrunsrv-patch.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20051112/3896507e/attachment.txt>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list