Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-25 Thread Christopher Faylor
On Fri, Nov 25, 2005 at 09:34:24PM +0100, Christian Franke wrote:
>Christopher Faylor wrote:
>>On Fri, Nov 25, 2005 at 08:43:43PM +0100, Christian Franke wrote:
>>>OK, let's forget the patch ;-)
>>
>>Actually, I have done some more testing myself and Windows doesn't work
>>the way that I remembered.  It seems like CTRL-BREAK isn't handled by
>>signal(SIGINT, ...).  So, I was wrong about this.
>
>MSVCRT maps CTRL-C to SIGINT, CTRL-BREAK to an extra SIGBREAK.  So it
>is possible to map this to SIGQUIT with a simple hack:
>
>#ifdef SIGBREAK
>#undef SIGQUIT
>#define SIGQUIT SIGBREAK
>#endif
>
>This isn't possible with Cygwin (in notty mode), because CTRL-C and
>CTRL-BREAK cannot be distinguished.

I'm not sure why you're reexplaining this after I said I'd incorporate
the patch but I'm not concerned about making no-cygwin programs work.  I
just didn't want to veer from what I thought was standard Windows
behavior in absence of any other standard.

cgf


Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-25 Thread Christian Franke

Christopher Faylor wrote:


On Fri, Nov 25, 2005 at 08:43:43PM +0100, Christian Franke wrote:
 


OK, let's forget the patch ;-)
   



Actually, I have done some more testing myself and Windows doesn't work
the way that I remembered.  It seems like CTRL-BREAK isn't handled by
signal(SIGINT, ...).  So, I was wrong about this.



MSVCRT maps CTRL-C to SIGINT, CTRL-BREAK to an extra SIGBREAK.
So it is possible to map this to SIGQUIT with a simple hack:

#ifdef SIGBREAK
#undef SIGQUIT
#define SIGQUIT SIGBREAK
#endif

This isn't possible with Cygwin (in notty mode), because CTRL-C and 
CTRL-BREAK cannot be distinguished.



I really should have
tested how it worked before rejecting your patch out of hand.
 



N.P. ;-)



So, this code is probably just reflecting my misperceptions of what
Windows was doing.  I'll add your patch as it improves Cygwin's
functionality.
 



Thanks!

Christian



Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-25 Thread Christopher Faylor
On Fri, Nov 25, 2005 at 08:43:43PM +0100, Christian Franke wrote:
>OK, let's forget the patch ;-)

Actually, I have done some more testing myself and Windows doesn't work
the way that I remembered.  It seems like CTRL-BREAK isn't handled by
signal(SIGINT, ...).  So, I was wrong about this.  I really should have
tested how it worked before rejecting your patch out of hand.

So, this code is probably just reflecting my misperceptions of what
Windows was doing.  I'll add your patch as it improves Cygwin's
functionality.

Thanks again for providing it.

cgf


Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-25 Thread Christian Franke

Christopher Faylor wrote:


[...]
It is (or should be, since I haven't checked it recently) supported if you
set CYGWIN=tty, though.  There is a lot of functionality that isn't available
with the normal windows console that is available with CYGWIN=tty.



Oh, Yes.

I tested this some time ago and it didn't work as expected, but now it 
works.

Hmm... must have missed something during first test, sorry.



Since
the only precedent for the behavior of CTRL-BREAK is MSVCRT, I am very
reluctant to change it.
 



OK, let's forget the patch ;-)


Christian



Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-25 Thread Christopher Faylor
On Fri, Nov 25, 2005 at 08:50:26AM +0100, Christian Franke wrote:
>Christopher Faylor wrote:
>>>[...]
>>>Suggest to add some option to send SIGQUIT via ^BREAK.
>>>
>>>A simple patch is attached.
>>>
>>>It sends SIGQUIT on ^BREAK if both VINTR and VQUIT are set to ^C.  As
>a
>>>positive side effect, this disables any other SIGQUIT key in termios.
>>
>>Sorry but the precedent of sending SIGINT when pressing CTRL-BREAK is
>>long-standing behavior that I am not comfortable changing.
>
>Agree.
>
>But the patch won't change this long standing-behavior unless the user
>opts-in via "stty quit ^C" (see testcase).
>
>So the patch shouldn't BREAK anything ;-)
>
>As an alternative, a new CYGWIN environment setting could be used.
>But using some termios setting for such an option is IMO the right thing
>to do.
>
>I missed the SIGQUIT via keyboard during the first port of smartd to
>Cygwin last year. In smartd's debug mode, SIGINT is used to reload
>configuration file, SIGQUIT to exit. This worked on every supported
>platform except Cygwin.

It is (or should be, since I haven't checked it recently) supported if you
set CYGWIN=tty, though.  There is a lot of functionality that isn't available
with the normal windows console that is available with CYGWIN=tty.  Since
the only precedent for the behavior of CTRL-BREAK is MSVCRT, I am very
reluctant to change it.

cgf


Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-24 Thread Christian Franke
Christopher Faylor wrote:
>>[...]
>>Suggest to add some option to send SIGQUIT via ^BREAK.
>>
>>A simple patch is attached.
>>
>>It sends SIGQUIT on ^BREAK if both VINTR and VQUIT are set to ^C.  As
a
>>positive side effect, this disables any other SIGQUIT key in termios.
>
>Sorry but the precedent of sending SIGINT when pressing CTRL-BREAK is
>long-standing behavior that I am not comfortable changing.

Agree.

But the patch won't change this long standing-behavior unless the user
opts-in via "stty quit ^C" (see testcase).

So the patch shouldn't BREAK anything ;-)

As an alternative, a new CYGWIN environment setting could be used.
But using some termios setting for such an option is IMO the right thing
to do.

I missed the SIGQUIT via keyboard during the first port of smartd to
Cygwin last year. In smartd's debug mode, SIGINT is used to reload
configuration file, SIGQUIT to exit. This worked on every supported
platform except Cygwin.
The Cygwin-specific workaround ("press ^C twice to quit") added to
smartd.c has more lines than this cygwin1.dll patch ;-)

Christian




Re: Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-24 Thread Christopher Faylor
On Thu, Nov 24, 2005 at 11:03:02PM +0100, Christian Franke wrote:
>unlike Linux & friends, Cygwin cannot send a SIGQUIT via keyboard.  The
>SIGQUIT key simulated in termios does only work if app reads from
>console.  Both console events ^C and ^BREAK are mapped to SIGINT.
>
>Suggest to add some option to send SIGQUIT via ^BREAK.
>
>A simple patch is attached.
>
>It sends SIGQUIT on ^BREAK if both VINTR and VQUIT are set to ^C.  As a
>positive side effect, this disables any other SIGQUIT key in termios.

Sorry but the precedent of sending SIGINT when pressing CTRL-BREAK is
long-standing behavior that I am not comfortable changing.

Thank you for the patch, though.

cgf


Allow to send SIGQUIT via Ctrl+BREAK (patch included)

2005-11-24 Thread Christian Franke

Hi,

unlike Linux & friends, Cygwin cannot send a SIGQUIT via keyboard.
The SIGQUIT key simulated in termios does only work if app reads from 
console.

Both console events ^C and ^BREAK are mapped to SIGINT.

Suggest to add some option to send SIGQUIT via ^BREAK.

A simple patch is attached.

It sends SIGQUIT on ^BREAK if both VINTR and VQUIT are set to ^C.
As a positive side effect, this disables any other SIGQUIT key in termios.

Testcase:

$ sleep 1000
[^BREAK]

$ ./stty quit ^C
$ sleep 1000
[^BREAK]
Quit (core dumped)

$ ./stty quit ^X
$ sleep 1000
[^BREAK]

$ echo Thanks for any comment
Thanks for any comment

Christian

--- exceptions.cc.orig  2005-07-01 17:49:40.00100 +0200
+++ exceptions.cc   2005-11-24 22:41:02.765867700 +0100
@@ -888,8 +888,13 @@
that we have handled the signal).  At this point, type should be
a CTRL_C_EVENT or CTRL_BREAK_EVENT. */
 {
+  int sig = SIGINT;
+  /* If intr and quit are both mapped to ^C, send SIGQUIT on ^BREAK */
+  if (type == CTRL_BREAK_EVENT
+  && t->ti.c_cc[VINTR] == 3 && t->ti.c_cc[VQUIT] == 3)
+sig = SIGQUIT;
   t->last_ctrl_c = GetTickCount ();
-  killsys (-myself->pid, SIGINT);
+  killsys (-myself->pid, sig);
   t->last_ctrl_c = GetTickCount ();
   return TRUE;
 }