delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/16/05:07:37

Date: Wed, 16 Nov 2005 11:07:30 +0100
From: Samuel Thibault <samuel DOT thibault AT ens-lyon DOT org>
To: cygwin AT cygwin DOT com
Subject: Re: Can I get a sigint when the bash window closed with close window's button?
Message-ID: <20051116100730.GN6300@implementation.labri.fr>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <897562721 AT web DOT de>
Mime-Version: 1.0
In-Reply-To: <897562721@web.de>
User-Agent: Mutt/1.5.9i-nntp
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hi,

Konrad Eisele, le Wed 16 Nov 2005 10:22:43 +0100, a écrit :
> I can get SIGINT when user presses ctrl-c, but when the user 
> closes the console by just clicking on the close button then 
> no signal handler is called. Neather SIGINT not SIGHUP. 
> Maybe it is not possible to get any notification by cygwin
> because cygwin is killed without notification too????
> Can there be a workaround somehow? Maybe there is 
> a windows hook or such?

I was looking for such thing some time ago, and couldn't find any useful
hook. And
http://msdn.microsoft.com/library/en-us/dllproc/base/setconsolectrlhandler.asp  says

« The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and
CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off,
or shuts down the system so that the process has an opportunity to clean
up before termination [thanks to SetConsoleCtrlHandler()]. Console
functions, or any C run-time functions that call console functions,
may not work reliably during processing of any of the three signals
mentioned previously. The reason is that some or all of the internal
console cleanup routines may have been called before executing the
process signal handler. »

So when the handler is called, it might already be too late...

Cygwin sets winsup/cygwin/exceptions.cc:ctrl_c_handler() as control
handler, and in the CTRL_CLOSE_EVENT case, returns FALSE, i.e. let
windows terminate the process, even if the user set a signal handler for
SIGHUP. Maybe cygwin could return TRUE in such case, so as to give the
application a chance to detach from the console and continue running?

Regards,
Samuel

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019