diff lib-src/emacsclient.c @ 53341:d4e6a050c9b1

Bugfix festival. lib-src/emacsclient.c (main_argc, main_argv): New variables. (main): Initialize them. (fail): Use them. (window_change, copy_from_to): Don't kill if emacs_pid is zero. (pty_conversation): Watch the command socket, too. Read emacs_pid here. Emacs and emacsclient could deadlock if Emacs tried to do a reset_sys_modes before sending its pid. lisp/server.el: Automatically delete the client frame when done editing. (server-frames): New variable. (server-process-filter, server-sentinel, server-buffer-done): Use it. (server-process-filter): Do a redisplay before evaluating other parameters. (Prevents "emacsclient -h -e '(delete-frame)'" from messing up the system. src/dispextern.h: Update prototypes. src/dispnew.c (window_change_signal): Do nothing if !term_initted. (init_display): Set the frame size from the tty data after term_init. src/emacs.c (main): Make sure things that init_sys_modes needs are initialized before init_display (which calls init_sys_modes now). (sort_args): Use xfree, not free. (shut_down_emacs) [!EMACS_HAVE_TTY_PGRP]: Use reset_all_sys_modes instead of reset_sys_modes. src/frame.c (make_terminal_frame): Sigh. Move terminal initialization back to the middle of frame setup. Handle errors by making sure that the delete_tty() called from term_init() will see and delete this frame. (Fdelete_frame): Kill the frame before calling delete_tty(). Fix condition for tty deletion. src/keyboard.c (Fset_input_mode): Use reset_sys_modes on the current terminal only. src/lisp.h: Remove duplicate prototypes. src/msdos.c (croak): use reset_all_sys_modes(). src/sysdeps.c (init_baud_rate): Added tty parameter, use it instead of CURTTY. (child_setup_tty): Reset sigio on stdin, not CURTTY(). (reset_sigio): Added fd parameter, put explicit fcntl there. (request_sigio, unrequest_sigio)[FASYNC]: Simply block/unblock the SIGIO signal, don't touch the file params. There are multiple ttys now, and we can't disable the SIGIO from emacsclient. (get_tty_size)[VMS]: Use tty_out instead of CURTTY(). (reset_sys_modes): Don't call cursor_to, clear_end_of_line; call cmgoto and tty_clear_end_of_line instead. The frame may already be dead. Updated reset_sigio call. src/term.c (clear_and_of_line): Separate tty-dependent stuff to tty_clear_end_of_line() for reset_sys_modes. (tty_clear_end_of_line): New function. (term_init): Added frame parameter, don't use selected_frame. Set the frame's output_data.tty value (in case there is an error later). Set the frame size in Wcm, not in the frame. Only free the termcap buffer if there is a termcap-related error. Call init_sys_modes last, not first. (deleting_tty): New variable. (delete_tty): Use it for handling recursive calls. Free deleted tty, except its Wcm (there is still a dangling reference somewhere). git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-19
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 29 Dec 2003 07:16:26 +0000
parents fe9b37bee5f7
children 201b17b0f2e5
line wrap: on
line diff
--- a/lib-src/emacsclient.c	Sun Dec 28 22:28:52 2003 +0000
+++ b/lib-src/emacsclient.c	Mon Dec 29 07:16:26 2003 +0000
@@ -102,6 +102,12 @@
 /* Name used to invoke this program.  */
 char *progname;
 
+/* The first argument to main. */
+int main_argc;
+
+/* The second argument to main. */
+char **main_argv;
+
 /* Nonzero means don't wait for a response from Emacs.  --no-wait.  */
 int nowait = 0;
 
@@ -294,14 +300,12 @@
   defined-- exit with an errorcode.
 */
 void
-fail (argc, argv)
-     int argc;
-     char **argv;
+fail ()
 {
   if (alternate_editor)
     {
       int i = optind - 1;
-      execvp (alternate_editor, argv + i);
+      execvp (alternate_editor, main_argv + i);
       return;
     }
   else
@@ -603,7 +607,7 @@
 #endif /* not SunOS-style */
 #endif /* not BSD-style */
 
-  if (width != 0 && height != 0)
+  if (emacs_pid && width && height)
     kill (emacs_pid, SIGWINCH);
 }
 
@@ -721,7 +725,7 @@
       if (r < 0)
         return 0;               /* Error */
 
-      if (sigio)
+      if (emacs_pid && sigio)
         {
           kill (emacs_pid, SIGIO);
         }
@@ -730,8 +734,10 @@
 }
 
 int
-pty_conversation ()
+pty_conversation (FILE *in)
 {
+  char *str;
+  char string[BUFSIZ];              
   fd_set set;
 
   in_conversation = 1;
@@ -742,6 +748,7 @@
     FD_ZERO (&set);
     FD_SET (master, &set);
     FD_SET (1, &set);
+    FD_SET (fileno (in), &set);
     res = select (FD_SETSIZE, &set, NULL, NULL, NULL);
     if (res < 0)
       {
@@ -762,6 +769,24 @@
             if (! copy_from_to (1, master, 1))
               return 1;
           }
+        if (FD_ISSET (fileno (in), &set))
+          {
+            if (! emacs_pid)
+              {
+                /* Get the pid of the Emacs process.
+                   XXX Is there is some nifty libc/kernel feature for doing this?
+                */
+                str = fgets (string, BUFSIZ, in);
+                if (! str)
+                  {
+                    reset_tty ();
+                    fprintf (stderr, "%s: %s\n", progname, str);
+                    fail ();
+                  }
+                
+                emacs_pid = atoi (str);
+              }
+          }
       }
   }
   return 1;
@@ -828,6 +853,8 @@
   char *cwd, *str;
   char string[BUFSIZ];
 
+  main_argc = argc;
+  main_argv = argv;
   progname = argv[0];
 
   /* Process options.  */
@@ -1087,19 +1114,7 @@
 
   if (here)
     {
-      /* First of all, get the pid of the Emacs process.
-         XXX Is there is some nifty libc/kernel feature for doing this?
-       */
-      str = fgets (string, BUFSIZ, in);
-      emacs_pid = atoi (str);
-      if (emacs_pid == 0)
-        {
-          reset_tty ();
-          fprintf (stderr, "%s: %s\n", argv[0], str);
-          fail (argc, argv);
-        }
-      
-      if (! pty_conversation ())
+      if (! pty_conversation (out))
         {
           reset_tty ();
           fprintf (stderr, "%s: ", argv[0]);