From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ami Fischman" Newsgroups: gmane.emacs.devel Subject: Re: poor handling of multiple C-g with multi-tty (apparent hangs) Date: Mon, 15 Sep 2008 16:00:39 -0700 Message-ID: <9aa0cfde0809151600h6d61c248g3e801ccc3d363cc2@mail.gmail.com> References: <48a85bf8.02a6420a.410f.ffffc5a1MFETCHER_ADDED@google.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_19028_23114748.1221519639399" X-Trace: ger.gmane.org 1221519730 17197 80.91.229.12 (15 Sep 2008 23:02:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Sep 2008 23:02:10 +0000 (UTC) Cc: emacs-devel@gnu.org To: "Chong Yidong" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 16 01:03:05 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KfN4q-0000xK-HA for ged-emacs-devel@m.gmane.org; Tue, 16 Sep 2008 01:01:53 +0200 Original-Received: from localhost ([127.0.0.1]:35973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KfN3o-0006pG-AS for ged-emacs-devel@m.gmane.org; Mon, 15 Sep 2008 19:00:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KfN3j-0006n8-96 for emacs-devel@gnu.org; Mon, 15 Sep 2008 19:00:43 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KfN3i-0006mN-6K for emacs-devel@gnu.org; Mon, 15 Sep 2008 19:00:42 -0400 Original-Received: from [199.232.76.173] (port=50703 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KfN3i-0006mE-2T for emacs-devel@gnu.org; Mon, 15 Sep 2008 19:00:42 -0400 Original-Received: from wf-out-1314.google.com ([209.85.200.173]:15795) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KfN3h-0003K3-5m for emacs-devel@gnu.org; Mon, 15 Sep 2008 19:00:41 -0400 Original-Received: by wf-out-1314.google.com with SMTP id 28so2290285wfc.24 for ; Mon, 15 Sep 2008 16:00:39 -0700 (PDT) Original-Received: by 10.142.251.9 with SMTP id y9mr84812wfh.46.1221519639404; Mon, 15 Sep 2008 16:00:39 -0700 (PDT) Original-Received: by 10.143.11.8 with HTTP; Mon, 15 Sep 2008 16:00:39 -0700 (PDT) In-Reply-To: <48a85bf8.02a6420a.410f.ffffc5a1MFETCHER_ADDED@google.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:103893 Archived-At: ------=_Part_19028_23114748.1221519639399 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline This was never checked in, even though it is strictly an improvement to the current situation (see my original email for why I believe this is an improvement to emacs users as a whole). Are you still working on refining it or would you mind checking it in as it is? -a On Mon, Aug 11, 2008 at 10:40 AM, Chong Yidong wrote: > "Ami Fischman" writes: > > > Emacs has code to deal with C-g being entered while a quit is already > > in progress, meant to suspend emacs and drop the user to the superior > > shell or debugger (see section 59.7 Emergency Escape of the emacs > > info). This is done if emacs believes it's a good idea, which > > criteria includes "running in tty mode". Unfortunately this was never > > updated to work correctly with the multi-tty patch. > > Thanks for pointing this out. > > IIUC, the "emergency C-g" behavior is geared towards the traditional > setup where there's only one text-only terminal available. There, the > emergency C-g is the only way to drop back to the shell if Emacs gets > stuck. > > It's disabled for graphical terminals because there, you can open up a > separate terminal to kill/suspend the Emacs process. > > This implies that we should disable the emergency C-g if Emacs is > running on more than one terminal, as in the following patch. > > *** trunk/src/keyboard.c.~1.969.~ 2008-08-05 17:08:23.000000000 -0400 > --- trunk/src/keyboard.c 2008-08-11 13:35:43.000000000 -0400 > *************** > *** 10953,10958 **** > --- 10953,10976 ---- > errno = old_errno; > } > > + /* If there is exactly one terminal active, return it. Otherwise, > + return NULL. */ > + > + static struct terminal * > + just_one_tty_p () > + { > + struct terminal *t, *found = NULL; > + for (t = terminal_list; t; t = t->next_terminal) > + if (TERMINAL_ACTIVE_P (t)) > + { > + if (found) > + return NULL; > + else > + found = t; > + } > + return found; > + } > + > /* This routine is called at interrupt level in response to C-g. > > It is called from the SIGINT handler or kbd_buffer_store_event. > *************** > *** 10968,10980 **** > handle_interrupt () > { > char c; > > cancel_echoing (); > > - /* XXX This code needs to be revised for multi-tty support. */ > if (!NILP (Vquit_flag) > #ifndef MSDOS > ! && get_named_tty ("/dev/tty") > #endif > ) > { > --- 10986,10999 ---- > handle_interrupt () > { > char c; > + struct terminal *t; > > cancel_echoing (); > > if (!NILP (Vquit_flag) > #ifndef MSDOS > ! && (t = just_one_tty_p (), t) > ! && t->type == output_termcap > #endif > ) > { > ------=_Part_19028_23114748.1221519639399 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
This was never checked in, even though it is strictly an improvement to the current situation (see my original email for why I believe this is an improvement to emacs users as a whole).  Are you still working on refining it or would you mind checking it in as it is?

-a

On Mon, Aug 11, 2008 at 10:40 AM, Chong Yidong <cyd@stupidchicken.com> wrote:
"Ami Fischman" <ami@fischman.org> writes:

> Emacs has code to deal with C-g being entered while a quit is already
> in progress, meant to suspend emacs and drop the user to the superior
> shell or debugger (see section 59.7 Emergency Escape of the emacs
> info).  This is done if emacs believes it's a good idea, which
> criteria includes "running in tty mode".  Unfortunately this was never
> updated to work correctly with the multi-tty patch.

Thanks for pointing this out.

IIUC, the "emergency C-g" behavior is geared towards the traditional
setup where there's only one text-only terminal available.  There, the
emergency C-g is the only way to drop back to the shell if Emacs gets
stuck.

It's disabled for graphical terminals because there, you can open up a
separate terminal to kill/suspend the Emacs process.

This implies that we should disable the emergency C-g if Emacs is
running on more than one terminal, as in the following patch.

*** trunk/src/keyboard.c.~1.969.~       2008-08-05 17:08:23.000000000 -0400
--- trunk/src/keyboard.c        2008-08-11 13:35:43.000000000 -0400
***************
*** 10953,10958 ****
--- 10953,10976 ----
   errno = old_errno;
 }

+ /* If there is exactly one terminal active, return it.  Otherwise,
+    return NULL.  */
+
+ static struct terminal *
+ just_one_tty_p ()
+ {
+   struct terminal *t, *found = NULL;
+   for (t = terminal_list; t; t = t->next_terminal)
+     if (TERMINAL_ACTIVE_P (t))
+       {
+       if (found)
+         return NULL;
+       else
+         found = t;
+       }
+   return found;
+ }
+
 /* This routine is called at interrupt level in response to C-g.

    It is called from the SIGINT handler or kbd_buffer_store_event.
***************
*** 10968,10980 ****
 handle_interrupt ()
 {
   char c;

   cancel_echoing ();

-   /* XXX This code needs to be revised for multi-tty support. */
   if (!NILP (Vquit_flag)
 #ifndef MSDOS
!       && get_named_tty ("/dev/tty")
 #endif
       )
     {
--- 10986,10999 ----
 handle_interrupt ()
 {
   char c;
+   struct terminal *t;

   cancel_echoing ();

   if (!NILP (Vquit_flag)
 #ifndef MSDOS
!       && (t = just_one_tty_p (), t)
!       && t->type == output_termcap
 #endif
       )
     {

------=_Part_19028_23114748.1221519639399--