diff src/term.c @ 83525:b2e7507b55c6

Fix C-x 5 2 on the controlling tty; fix some possible crash conditions and a memory leak. * src/frame.c (make_terminal_frame): Don't create frames on a terminal that is being deleted. * src/xfns.c (Fx_create_frame, x_create_tip_frame): Ditto. * src/keyboard.c (tty_read_avail_input): Don't read from a terminal that is being deleted. * src/term.c (get_named_tty): Abort if tty name is NULL. Simplify accordingly. * src/term.c (Ftty_type): Return nil if terminal is not on a tty instead of throwing an error. Doc update. * src/term.c (init_tty): Set name before calling `get_named_tty'. * src/term.c (delete_tty): Let delete_terminal delete the frames. Plug memory leak caused by tty->name. Remove reference to `deleting_tty'. * src/term.c (syms_of_term) <Vsuspend_tty_functions, Vresume_tty_functions>: Doc update. * src/termhooks.h (terminal) <name>: Explain why identifying terminals by name is a bad idea. * src/terminal.c (delete_terminal): Doc update. * src/xterm.c (XTread_socket): Disable loop on all X displays. * src/xterm.c (x_delete_display): Doc update to reflect changes in delete_terminal. * src/xterm.c (x_delete_terminal): Don't set terminal->deleted and let delete_terminal delete the frames on the terminal. * src/xterm.h (x_display_info) <terminal>: Move member earlier in the struct. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-565
author Karoly Lorentey <lorentey@elte.hu>
date Sat, 20 May 2006 17:12:43 +0000
parents a5d712e6585a
children c71725faff1a
line wrap: on
line diff
--- a/src/term.c	Sat May 20 17:02:47 2006 +0000
+++ b/src/term.c	Sat May 20 17:12:43 2006 +0000
@@ -2029,9 +2029,8 @@
   return t;
 }
 
-/* Return the active termcap device that uses the tty device with the
-   given name.  If NAME is NULL, return the device corresponding to
-   our controlling terminal.
+/* Return an active termcap device that uses the tty device with the
+   given name.
 
    This function ignores suspended devices.
 
@@ -2043,14 +2042,16 @@
 {
   struct terminal *t;
 
-  for (t = terminal_list; t; t = t->next_terminal) {
-    if (t->type == output_termcap
-        && ((t->display_info.tty->name == 0 && name == 0)
-            || (name && t->display_info.tty->name
-                && !strcmp (t->display_info.tty->name, name)))
-        && TERMINAL_ACTIVE_P (t))
-      return t;
-  };
+  if (!name)
+    abort ();
+
+  for (t = terminal_list; t; t = t->next_terminal)
+    {
+      if (t->type == output_termcap
+          && !strcmp (t->display_info.tty->name, name)
+          && TERMINAL_ACTIVE_P (t))
+        return t;
+    }
 
   return 0;
 }
@@ -2058,6 +2059,7 @@
 
 DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
        doc: /* Return the type of the tty device that TERMINAL uses.
+Returns nil if TERMINAL is not on a tty device.
 
 TERMINAL can be a terminal id, a frame or nil (meaning the selected
 frame's terminal).  */)
@@ -2067,8 +2069,8 @@
   struct terminal *t = get_terminal (terminal, 1);
 
   if (t->type != output_termcap)
-    error ("Terminal %d is not a termcap terminal", t->id);
-           
+    return Qnil;
+
   if (t->display_info.tty->type)
     return build_string (t->display_info.tty->type);
   else
@@ -2388,7 +2390,7 @@
 /* Create a termcap display on the tty device with the given name and
    type.
 
-   If NAME is NULL, then use the controlling tty, i.e., stdin/stdout.
+   If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
    Otherwise NAME should be a path to the tty device file,
    e.g. "/dev/pts/7".
 
@@ -2414,6 +2416,11 @@
                  "Unknown terminal type",
                  "Unknown terminal type");
 
+  if (name == NULL)
+    name = "/dev/tty";
+  if (!strcmp (name, "/dev/tty"))
+    ctty = 1;
+
   /* If we already have a terminal on the given device, use that.  If
      all such terminals are suspended, create a new one instead.  */
   /* XXX Perhaps this should be made explicit by having init_tty
@@ -2438,11 +2445,6 @@
 
   set_tty_hooks (terminal);
   
-  if (name == NULL)
-    name = "/dev/tty";
-  if (!strcmp (name, "/dev/tty"))
-    ctty = 1;
-
   {
     int fd;
     FILE *file;
@@ -2977,11 +2979,10 @@
 {
   struct tty_display_info *tty;
   Lisp_Object tail, frame;
-  char *tty_name;
   int last_terminal;
   
-  /* Protect against recursive calls.  Fdelete_frame calls us back
-     when we delete our last frame.  */
+  /* Protect against recursive calls.  Fdelete_frame in
+     delete_terminal calls us back when it deletes our last frame.  */
   if (terminal->deleted)
     return;
 
@@ -3019,25 +3020,15 @@
       tty->next = 0;
     }
 
-  /* We must not throw any errors below this line.  */
-  terminal->deleted = 1;
-
-  FOR_EACH_FRAME (tail, frame)
-    {
-      struct frame *f = XFRAME (frame);
-      if (FRAME_TERMCAP_P (f) && FRAME_LIVE_P (f) && FRAME_TTY (f) == tty)
-        {
-          Fdelete_frame (frame, Qt);
-        }
-    }
-
   /* reset_sys_modes needs a valid device, so this call needs to be
      before delete_terminal. */
   reset_sys_modes (tty);
 
   delete_terminal (terminal);
 
-  tty_name = tty->name;
+  if (tty->name)
+    xfree (tty->name);
+
   if (tty->type)
     xfree (tty->type);
 
@@ -3060,7 +3051,6 @@
 
   bzero (tty, sizeof (struct tty_display_info));
   xfree (tty);
-  deleting_tty = 0;
 }
 
 
@@ -3096,14 +3086,14 @@
 
   DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions,
     doc: /* Functions to be run after suspending a tty.
-The functions are run with one argument, the name of the tty to be suspended.
+The functions are run with one argument, the terminal id to be suspended.
 See `suspend-tty'.  */);
   Vsuspend_tty_functions = Qnil;
 
 
   DEFVAR_LISP ("resume-tty-functions", &Vresume_tty_functions,
     doc: /* Functions to be run after resuming a tty.
-The functions are run with one argument, the name of the tty that was revived.
+The functions are run with one argument, the terminal id that was revived.
 See `resume-tty'.  */);
   Vresume_tty_functions = Qnil;