Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <437751C0.0@t-online.de> Date: Sun, 13 Nov 2005 15:46:24 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b) Gecko/20050217 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: cygrunsrv hangs forever on exec error (fix included) References: <43761BF8 DOT 9030603 AT t-online DOT de> <20051113131927 DOT GA3462 AT calimero DOT vinschen DOT de> In-Reply-To: <20051113131927.GA3462@calimero.vinschen.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-ID: E60q8mZCoeLMJazqeUZlNea0vrVzpvWA5zyKu2y+TcdDGdgA+dBEcR X-TOI-MSGID: 1275ce8c-70bd-46a9-b67e-4e8eb412939f X-IsSubscribed: yes 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/