comparison 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
comparison
equal deleted inserted replaced
53340:db645482d6bc 53341:d4e6a050c9b1
99 #define VERSION "unspecified" 99 #define VERSION "unspecified"
100 #endif 100 #endif
101 101
102 /* Name used to invoke this program. */ 102 /* Name used to invoke this program. */
103 char *progname; 103 char *progname;
104
105 /* The first argument to main. */
106 int main_argc;
107
108 /* The second argument to main. */
109 char **main_argv;
104 110
105 /* Nonzero means don't wait for a response from Emacs. --no-wait. */ 111 /* Nonzero means don't wait for a response from Emacs. --no-wait. */
106 int nowait = 0; 112 int nowait = 0;
107 113
108 /* Nonzero means args are expressions to be evaluated. --eval. */ 114 /* Nonzero means args are expressions to be evaluated. --eval. */
292 /* 298 /*
293 Try to run a different command, or --if no alternate editor is 299 Try to run a different command, or --if no alternate editor is
294 defined-- exit with an errorcode. 300 defined-- exit with an errorcode.
295 */ 301 */
296 void 302 void
297 fail (argc, argv) 303 fail ()
298 int argc;
299 char **argv;
300 { 304 {
301 if (alternate_editor) 305 if (alternate_editor)
302 { 306 {
303 int i = optind - 1; 307 int i = optind - 1;
304 execvp (alternate_editor, argv + i); 308 execvp (alternate_editor, main_argv + i);
305 return; 309 return;
306 } 310 }
307 else 311 else
308 { 312 {
309 exit (1); 313 exit (1);
601 ioctl (master, TIOCGSIZE, &size); 605 ioctl (master, TIOCGSIZE, &size);
602 } 606 }
603 #endif /* not SunOS-style */ 607 #endif /* not SunOS-style */
604 #endif /* not BSD-style */ 608 #endif /* not BSD-style */
605 609
606 if (width != 0 && height != 0) 610 if (emacs_pid && width && height)
607 kill (emacs_pid, SIGWINCH); 611 kill (emacs_pid, SIGWINCH);
608 } 612 }
609 613
610 int in_conversation = 0; 614 int in_conversation = 0;
611 int quit_conversation = 0; 615 int quit_conversation = 0;
719 || (r > 0 && (written += r) && written != nread)); 723 || (r > 0 && (written += r) && written != nread));
720 724
721 if (r < 0) 725 if (r < 0)
722 return 0; /* Error */ 726 return 0; /* Error */
723 727
724 if (sigio) 728 if (emacs_pid && sigio)
725 { 729 {
726 kill (emacs_pid, SIGIO); 730 kill (emacs_pid, SIGIO);
727 } 731 }
728 } 732 }
729 return 1; 733 return 1;
730 } 734 }
731 735
732 int 736 int
733 pty_conversation () 737 pty_conversation (FILE *in)
734 { 738 {
739 char *str;
740 char string[BUFSIZ];
735 fd_set set; 741 fd_set set;
736 742
737 in_conversation = 1; 743 in_conversation = 1;
738 744
739 while (! quit_conversation) { 745 while (! quit_conversation) {
740 int res; 746 int res;
741 747
742 FD_ZERO (&set); 748 FD_ZERO (&set);
743 FD_SET (master, &set); 749 FD_SET (master, &set);
744 FD_SET (1, &set); 750 FD_SET (1, &set);
751 FD_SET (fileno (in), &set);
745 res = select (FD_SETSIZE, &set, NULL, NULL, NULL); 752 res = select (FD_SETSIZE, &set, NULL, NULL, NULL);
746 if (res < 0) 753 if (res < 0)
747 { 754 {
748 if (errno != EINTR) 755 if (errno != EINTR)
749 return 0; 756 return 0;
760 { 767 {
761 /* Forward user input to Emacs. */ 768 /* Forward user input to Emacs. */
762 if (! copy_from_to (1, master, 1)) 769 if (! copy_from_to (1, master, 1))
763 return 1; 770 return 1;
764 } 771 }
772 if (FD_ISSET (fileno (in), &set))
773 {
774 if (! emacs_pid)
775 {
776 /* Get the pid of the Emacs process.
777 XXX Is there is some nifty libc/kernel feature for doing this?
778 */
779 str = fgets (string, BUFSIZ, in);
780 if (! str)
781 {
782 reset_tty ();
783 fprintf (stderr, "%s: %s\n", progname, str);
784 fail ();
785 }
786
787 emacs_pid = atoi (str);
788 }
789 }
765 } 790 }
766 } 791 }
767 return 1; 792 return 1;
768 } 793 }
769 794
826 FILE *out, *in; 851 FILE *out, *in;
827 struct sockaddr_un server; 852 struct sockaddr_un server;
828 char *cwd, *str; 853 char *cwd, *str;
829 char string[BUFSIZ]; 854 char string[BUFSIZ];
830 855
856 main_argc = argc;
857 main_argv = argv;
831 progname = argv[0]; 858 progname = argv[0];
832 859
833 /* Process options. */ 860 /* Process options. */
834 decode_options (argc, argv); 861 decode_options (argc, argv);
835 862
1085 return 0; 1112 return 0;
1086 } 1113 }
1087 1114
1088 if (here) 1115 if (here)
1089 { 1116 {
1090 /* First of all, get the pid of the Emacs process. 1117 if (! pty_conversation (out))
1091 XXX Is there is some nifty libc/kernel feature for doing this?
1092 */
1093 str = fgets (string, BUFSIZ, in);
1094 emacs_pid = atoi (str);
1095 if (emacs_pid == 0)
1096 {
1097 reset_tty ();
1098 fprintf (stderr, "%s: %s\n", argv[0], str);
1099 fail (argc, argv);
1100 }
1101
1102 if (! pty_conversation ())
1103 { 1118 {
1104 reset_tty (); 1119 reset_tty ();
1105 fprintf (stderr, "%s: ", argv[0]); 1120 fprintf (stderr, "%s: ", argv[0]);
1106 perror ("fdopen"); 1121 perror ("fdopen");
1107 fail (argc, argv); 1122 fail (argc, argv);