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: Can I get a sigint when the bash window closed with close window's button?

On Tue, 15 Nov 2005, Joe Smith wrote:

> "Igor Pechtchanski" <pechtcha@XX.XXX.XXX> wrote in message">

<>.  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, 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.
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,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:
Problem reports:

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