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 Date: Wed, 1 Oct 2003 07:37:34 -0400 From: Jason Tishler To: The Cygwin Mailing List Subject: cygipc shutdown patch Message-ID: <20031001113733.GA2196@tishler.net> Mail-Followup-To: The Cygwin Mailing List Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline User-Agent: Mutt/1.4i --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Chuck, On Wed, Sep 03, 2003 at 03:31:02AM -0400, Charles Wilson wrote: > * Automatic removal of /tmp/MultiFileXXX files on [normal] daemon > shutdown (MH) The attached patch expands "normal" above to include the following two cases: 1. SIGINT, SIGQUIT, and SIGTERM signals when running as a process 2. SERVICE_CONTROL_SHUTDOWN requests when running as a service Now ipc-daemon2 will clean up after itself during system shutdown as requested by this user: http://archives.postgresql.org/pgsql-cygwin/2003-09/msg00168.php Thanks, Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ipc-daemon.c.diff" --- cygipc-2.01.orig/ipc-daemon.c 2003-07-13 16:27:50.000000000 -0400 +++ cygipc-2.01/ipc-daemon.c 2003-09-30 16:15:04.172763200 -0400 @@ -260,6 +260,22 @@ static int create_map(const char *pcName return iRv; } +void send_stop(void) +{ + if (hStopEvent) { + log_message(stderr, LOG_INFO, "sending hStopEvent"); + SetEvent(hStopEvent); + } + else + log_message(stderr, LOG_INFO, "no hStopEvent to send"); +} + +void signal_handler(int sig) +{ + log_message(stderr, LOG_INFO, "received signal '%d'", sig); + send_stop(); +} + int work_main(void) { int iRv; @@ -278,6 +294,10 @@ int work_main(void) int LComptShm = 0 ; int LRet ; + signal(SIGINT, signal_handler); + signal(SIGQUIT, signal_handler); + signal(SIGTERM, signal_handler); + do { /* dummy loop */ iRv = 1; @@ -664,16 +684,12 @@ service_handler(DWORD ctrl) cygwin_internal (CW_INIT_EXCEPTIONS, &except_list); switch (ctrl) { case SERVICE_CONTROL_STOP: + case SERVICE_CONTROL_SHUTDOWN: ss.dwCheckPoint = 1; ss.dwWaitHint = 3000L; // wait up to 3 seconds... ss.dwCurrentState = SERVICE_STOP_PENDING; - if (hStopEvent) { - log_message(stderr, LOG_INFO, "sending hStopEvent"); - SetEvent(hStopEvent); - } - else - log_message(stderr, LOG_INFO, "no hStopEvent to send"); + send_stop(); break; default: @@ -701,7 +717,7 @@ service_main(DWORD argc, LPSTR *argv) } ss.dwServiceType = SERVICE_WIN32_SHARE_PROCESS; ss.dwCurrentState = SERVICE_START_PENDING; - ss.dwControlsAccepted = SERVICE_ACCEPT_STOP; + ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; ss.dwWin32ExitCode = NO_ERROR; ss.dwCheckPoint = 1; ss.dwWaitHint = 3000L; --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ipc-daemon.c.ChangeLog" 2003-09-30 Jason Tishler * ipc-daemon.c (send_stop): New function. (signal_handler): Ditto. (work_main): Set SIGINT, SIGQUIT, and SIGTERM signal handlers. (service_handler): Handle shutdown requests. Call send_stop() when stop or shutdown request is received. (service_main): Accept shutdown requests. --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii -- 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/ --HcAYCG3uE/tztfnV--