public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Signal handling in WIN32 console programs
@ 2009-01-19 19:07 avadekar
  2009-01-22 23:05 ` Andy Koppe
  0 siblings, 1 reply; 6+ messages in thread
From: avadekar @ 2009-01-19 19:07 UTC (permalink / raw)
  To: cygwin

I ran across something under minTTY that I've confirmed behaves the same way
in rxvt, but differs under both the native terminal and console2.  I expect
there is a good reason why this happens, and I'm quite willing to modify the
WIN32 app rather than pine for a change in minTTY to accomodate me.

But first I need to understand what is really happening and how I could deal
with it.

My WIN32 app is compiled under vc7 and uses signal() to trap SIGINT, SIGABRT
and SIGTERM.  If I run the application under console2 or a native terminal,
pressing ^C triggers the handler and the application stops programmatically
due to a state change made by the handler.

When I do the same under rxvt (not the X based one) or minTTY, the ^C stops
the process without the signal handler executing.  Similarly, even when run
from the native console, kill (-INT, -ABRT, -TERM) causes the application to
end without the handler catching the signal.

So I wonder if the native console passes the character to the process directly
whereas the minTTY/rxvt shells interpret it and send a signal that the native
app doesn't really understand properly.

If so, is there anything I can do within the WIN32 app to catch what is
getting to it from the signal and maintain programmatic control?


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Signal handling in WIN32 console programs
  2009-01-19 19:07 Signal handling in WIN32 console programs avadekar
@ 2009-01-22 23:05 ` Andy Koppe
  2009-01-22 23:21   ` Christopher Faylor
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Koppe @ 2009-01-22 23:05 UTC (permalink / raw)
  To: cygwin

avadekar@certicom.com wrote:
> My WIN32 app is compiled under vc7 and uses signal() to trap SIGINT, SIGABRT
> and SIGTERM.  If I run the application under console2 or a native terminal,
> pressing ^C triggers the handler and the application stops programmatically
> due to a state change made by the handler.
> 
> When I do the same under rxvt (not the X based one) or minTTY, the ^C stops
> the process without the signal handler executing.  Similarly, even when run
> from the native console, kill (-INT, -ABRT, -TERM) causes the application to
> end without the handler catching the signal.
> 
> So I wonder if the native console passes the character to the process directly
> whereas the minTTY/rxvt shells interpret it and send a signal that the native
> app doesn't really understand properly.

MinTTY and rxvt do not interpret the ^C keypress in any special way. 
They simply write a ^C (0x03) character to the child process' pty. The 
pty driver may translate that into a signal depending on the pty's line 
settings (as shown by stty). Sorry I don't know how ^C is processed in a 
Windows console or why the behaviour would be different with ptys.

Andy


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Signal handling in WIN32 console programs
  2009-01-22 23:05 ` Andy Koppe
@ 2009-01-22 23:21   ` Christopher Faylor
  2009-01-23  4:36     ` avadekar
  0 siblings, 1 reply; 6+ messages in thread
From: Christopher Faylor @ 2009-01-22 23:21 UTC (permalink / raw)
  To: cygwin

On Thu, Jan 22, 2009 at 09:58:08PM +0000, Andy Koppe wrote:
> avadekar@certicom.com wrote:
>>My WIN32 app is compiled under vc7 and uses signal() to trap SIGINT,
>>SIGABRT and SIGTERM.  If I run the application under console2 or a
>>native terminal, pressing ^C triggers the handler and the application
>>stops programmatically due to a state change made by the handler.  When
>>I do the same under rxvt (not the X based one) or minTTY, the ^C stops
>>the process without the signal handler executing.  Similarly, even when
>>run from the native console, kill (-INT, -ABRT, -TERM) causes the
>>application to end without the handler catching the signal.  So I
>>wonder if the native console passes the character to the process
>>directly whereas the minTTY/rxvt shells interpret it and send a signal
>>that the native app doesn't really understand properly.
>
>MinTTY and rxvt do not interpret the ^C keypress in any special way.
>They simply write a ^C (0x03) character to the child process' pty.  The
>pty driver may translate that into a signal depending on the pty's line
>settings (as shown by stty).  Sorry I don't know how ^C is processed in
>a Windows console or why the behaviour would be different with ptys.

The operative term here is, once again, "Windows Console".  A pure
Windows program running in MinTTY or rxvt does not have a windows
console and so won't see the type of SIGINT that the windows console
generates.

cgf

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Signal handling in WIN32 console programs
  2009-01-22 23:21   ` Christopher Faylor
@ 2009-01-23  4:36     ` avadekar
  2009-01-23 13:42       ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: avadekar @ 2009-01-23  4:36 UTC (permalink / raw)
  To: cygwin

On Thu, Jan 22, 2009 at 05:04:23PM -0500, Christopher Faylor wrote:
> On Thu, Jan 22, 2009 at 09:58:08PM +0000, Andy Koppe wrote:
> > avadekar@certicom.com wrote:
> >>My WIN32 app is compiled under vc7 and uses signal() to trap SIGINT,
> >>SIGABRT and SIGTERM.  If I run the application under console2 or a
> >>native terminal, pressing ^C triggers the handler and the application
> >>stops programmatically due to a state change made by the handler.  When
> >>I do the same under rxvt (not the X based one) or minTTY, the ^C stops
> >>the process without the signal handler executing.  Similarly, even when
> >>run from the native console, kill (-INT, -ABRT, -TERM) causes the
> >>application to end without the handler catching the signal.  So I
> >>wonder if the native console passes the character to the process
> >>directly whereas the minTTY/rxvt shells interpret it and send a signal
> >>that the native app doesn't really understand properly.
> >
> >MinTTY and rxvt do not interpret the ^C keypress in any special way.
> >They simply write a ^C (0x03) character to the child process' pty.  The
> >pty driver may translate that into a signal depending on the pty's line
> >settings (as shown by stty).  Sorry I don't know how ^C is processed in
> >a Windows console or why the behaviour would be different with ptys.
> 
> The operative term here is, once again, "Windows Console".  A pure
> Windows program running in MinTTY or rxvt does not have a windows
> console and so won't see the type of SIGINT that the windows console
> generates.

Is there something that I could do inside the native application code to catch
what it is getting?  I've tried SetConsoleCtrlhandler, but that also never
gets invoked prior to the process termination.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Signal handling in WIN32 console programs
  2009-01-23  4:36     ` avadekar
@ 2009-01-23 13:42       ` Corinna Vinschen
  2009-01-23 15:04         ` avadekar
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2009-01-23 13:42 UTC (permalink / raw)
  To: cygwin

On Jan 22 18:05, avadekar@certicom.com wrote:
> On Thu, Jan 22, 2009 at 05:04:23PM -0500, Christopher Faylor wrote:
> > On Thu, Jan 22, 2009 at 09:58:08PM +0000, Andy Koppe wrote:
> > > avadekar@certicom.com wrote:
> > >>  So I
> > >>wonder if the native console passes the character to the process
> > >>directly whereas the minTTY/rxvt shells interpret it and send a signal
> > >>that the native app doesn't really understand properly.
> > >
> > >MinTTY and rxvt do not interpret the ^C keypress in any special way.
> > >They simply write a ^C (0x03) character to the child process' pty.  The
> > >pty driver may translate that into a signal depending on the pty's line
> > >settings (as shown by stty).  Sorry I don't know how ^C is processed in
> > >a Windows console or why the behaviour would be different with ptys.
> > 
> > The operative term here is, once again, "Windows Console".  A pure
> > Windows program running in MinTTY or rxvt does not have a windows
> > console and so won't see the type of SIGINT that the windows console
> > generates.
> 
> Is there something that I could do inside the native application code to catch
> what it is getting?  I've tried SetConsoleCtrlhandler, but that also never
> gets invoked prior to the process termination.

No.  The Cygwin tty apps like rxvt and MinTTY are using POSIX signal
handling.  The implementation for that only exists in Cygwin and only
Cygwin applications are able to deal with them.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Signal handling in WIN32 console programs
  2009-01-23 13:42       ` Corinna Vinschen
@ 2009-01-23 15:04         ` avadekar
  0 siblings, 0 replies; 6+ messages in thread
From: avadekar @ 2009-01-23 15:04 UTC (permalink / raw)
  To: cygwin

On Fri, Jan 23, 2009 at 05:10:34AM -0500, Corinna Vinschen wrote:
> On Jan 22 18:05, avadekar@certicom.com wrote:
> > On Thu, Jan 22, 2009 at 05:04:23PM -0500, Christopher Faylor wrote:
> > > On Thu, Jan 22, 2009 at 09:58:08PM +0000, Andy Koppe wrote:
> > > > avadekar@certicom.com wrote:
> > > >>  So I
> > > >>wonder if the native console passes the character to the process
> > > >>directly whereas the minTTY/rxvt shells interpret it and send a signal
> > > >>that the native app doesn't really understand properly.
> > > >
> > > >MinTTY and rxvt do not interpret the ^C keypress in any special way.
> > > >They simply write a ^C (0x03) character to the child process' pty.  The
> > > >pty driver may translate that into a signal depending on the pty's line
> > > >settings (as shown by stty).  Sorry I don't know how ^C is processed in
> > > >a Windows console or why the behaviour would be different with ptys.
> > > 
> > > The operative term here is, once again, "Windows Console".  A pure
> > > Windows program running in MinTTY or rxvt does not have a windows
> > > console and so won't see the type of SIGINT that the windows console
> > > generates.
> > 
> > Is there something that I could do inside the native application code to catch
> > what it is getting?  I've tried SetConsoleCtrlhandler, but that also never
> > gets invoked prior to the process termination.
> 
> No.  The Cygwin tty apps like rxvt and MinTTY are using POSIX signal
> handling.  The implementation for that only exists in Cygwin and only
> Cygwin applications are able to deal with them.
> 
> Corinna

It seems that it ought to map to something, or else it wouldn't actually do
anything.  But given that you say I can't do what I'm trying within the posix
shell, I suppose I could have the application open its own console (which would
be native), and then a Ctrl-C in that window would presumably do what I want.

> 
> -- 
> Corinna Vinschen                  Please, send mails regarding Cygwin to
> Cygwin Project Co-Leader          cygwin AT cygwin DOT com
> Red Hat
> 
> --
> 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-01-23 14:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-19 19:07 Signal handling in WIN32 console programs avadekar
2009-01-22 23:05 ` Andy Koppe
2009-01-22 23:21   ` Christopher Faylor
2009-01-23  4:36     ` avadekar
2009-01-23 13:42       ` Corinna Vinschen
2009-01-23 15:04         ` avadekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).