cygrunsrv hangs forever on exec error (fix included)

Christian Franke Christian.Franke@t-online.de
Sun Nov 13 16:24:00 GMT 2005


Corinna Vinschen wrote:

>[...]
>
>Thanks for this report and the simple testcases.  The description
>is very helpful.  I just don't really like the idea to leave the
>service_main function through _exit.
>

Agree. But this is IMO the only way to let SCM automatically restart a 
failed service if desired.
A nonzero exitcode does not help, the process(!) must die prematurely 
without setting SERVICE_STOPPED.

I found all this via trial and error when adding service support to a 
legacy MFC app.
So this info might be incomplete and not "portable" to anything except XP.


>[...] 
>
>I didn't create a new cygrunsrv version for now, instead I'm sending
>my diff.  I would like to hear what you think and if I didn't made a
>fatal mistake, I'll uplaod a new cygrunsrv version with this changes.
>  
>

Patch looks OK (no time to really test now sorry), structure now much 
cleaner.
It should avoid the hang - except in the neverexists case.

In this case, service_main() still exits without setting SERVICE_STOPPED 
and SCM will waitforever for some thread doing this.
(Yes, SCM should check the thread count, but it doesn't)

Suggest ugly but possibly working:

      if (neverexits && !shutting_down)
        {
          syslog (LOG_ERR, "`%s' service exited prematurely with "
              "exit status: %u", svcname, s);
          /* Do not report that the service is stopped so that if
         recovery options are set, Windows will automatically
         restart the service. */
          service_main_exitval = s;
+         _exit(service_main_exitval);
        }

and:

      if (!StartServiceCtrlDispatcherA(ste))
        return error (StartAsSvcErr);
+     sleep(1);
      return service_main_exitval;

to let service_main() end gracefully in the SERVICE_STOPPED case.

Christian


--
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