delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/16/04:22:55

Date: Wed, 16 Nov 2005 10:22:43 +0100
Message-Id: <897562721@web.de>
MIME-Version: 1.0
From: Konrad Eisele <eiselekd AT web DOT de>
To: cygwin AT cygwin DOT com
Subject: Re: Can I get a sigint when the bash window closed with close window's button?
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

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?

---------------------- main.c ------------------------
#include <signal.h>
#include <stdio.h>

void func1() {
  FILE *current;
  current=fopen("func1.txt","a");
  fprintf(current,"func1 called");
  fclose(current);
  while(1) {
    printf("func1\n");
  }
}

void func2() {
  FILE *current;
  current=fopen("func2.txt","a");
  fprintf(current,"func2 called");
  fclose(current);
  while(1) {
    printf("func2\n");
  }
}

int main() {
  signal (SIGHUP, func1);
  signal (SIGINT, func2);
  while(1) {};
}

--------------------------------------------------



cygwin AT cygwin DOT com schrieb am 16.11.05 00:00:50:
> 
> On Tue, 15 Nov 2005, Joe Smith wrote:
> 
> > "Igor Pechtchanski" <pechtcha AT XX DOT XXX DOT XXX> wrote in message news:Pine DOT GSO DOT 4 DOT 63 DOT 0511151424250 DOT 15491 AT slinky DOT cs DOT nyu DOT edu...
> 
> <http://cygwin.com/acronyms/#PCYMTNQREAIYR>.  Thanks.
> 
> > > On Tue, 15 Nov 2005, Konrad Eisele wrote:
> > >
> > > > When th cygwin bash window is closed by clicking on the window's
> > > > close button the the appliaction gets killed without recieving a
> > > > sigint or any atexit called. Is there a way to be able to run
> > > > cleanup code when the application is about to be killed?
> > >
> > > According to exceptions.cc, a SIGHUP will be sent to bash in this
> > > case. Are you handling the right signal?
> > >
> > > BTW, the atexit() callback also should be called -- do you have a
> > > simple testcase to reproduce the problem?
> > > Igor
> >
> > I know nothing about signals, but this program when run inside bash does
> > not seem to run callback() *ever*.
> > ^c does not run it. Closing the bash window does not run it. But if you
> > remove the loop then it *is* run.
> >
> > #include <stdio.h>
> > void callback()
> > {
> >  FILE *current;
> >
> >  current=fopen("test.txt","a");
> >  fprintf(current,"atexit");
> > }
> >
> > int main()
> > {
> >  atexit(*callback);
> >  while(1)
> >  {};
> > }
> 
> IIRC, the atexit callback is not supposed to be invoked from a default
> signal handler.  In fact, Cygwin defines a signal_exit specifically to
> avoid invoking it.  If you change the above to terminate on something
> other than a signal (e.g., a condition in the loop), your callback will be
> invoked.  Adding a signal handler that calls exit() should also cause the
> callback to be invoked.
> 	Igor
> -- 
> 				http://cs.nyu.edu/~pechtcha/
>       |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
> ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
>      |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
>     '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!
> 
> If there's any real truth it's that the entire multidimensional infinity
> of the Universe is almost certainly being run by a bunch of maniacs. /DA
> 
> --
> 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/
> 



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