This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cygrunsrv hangs forever on exec error (fix included)

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


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

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


-- Unsubscribe info: Problem reports: Documentation: FAQ:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]