Mercurial > emacs
comparison src/sysdep.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 | 21720c013048 |
comparison
equal
deleted
inserted
replaced
53340:db645482d6bc | 53341:d4e6a050c9b1 |
---|---|
182 #include "termhooks.h" | 182 #include "termhooks.h" |
183 #include "termchar.h" | 183 #include "termchar.h" |
184 #include "termopts.h" | 184 #include "termopts.h" |
185 #include "dispextern.h" | 185 #include "dispextern.h" |
186 #include "process.h" | 186 #include "process.h" |
187 #include "cm.h" /* for reset_sys_modes */ | |
187 | 188 |
188 #ifdef WINDOWSNT | 189 #ifdef WINDOWSNT |
189 #include <direct.h> | 190 #include <direct.h> |
190 /* In process.h which conflicts with the local copy. */ | 191 /* In process.h which conflicts with the local copy. */ |
191 #define _P_WAIT 0 | 192 #define _P_WAIT 0 |
328 } | 329 } |
329 | 330 |
330 #endif /* SIGTSTP */ | 331 #endif /* SIGTSTP */ |
331 | 332 |
332 void | 333 void |
333 init_baud_rate () | 334 init_baud_rate (struct tty_output *tty) |
334 { | 335 { |
335 if (noninteractive) | 336 if (noninteractive) |
336 emacs_ospeed = 0; | 337 emacs_ospeed = 0; |
337 else | 338 else |
338 { | 339 { |
343 emacs_ospeed = 15; | 344 emacs_ospeed = 15; |
344 #else /* not DOS_NT */ | 345 #else /* not DOS_NT */ |
345 #ifdef VMS | 346 #ifdef VMS |
346 struct sensemode sg; | 347 struct sensemode sg; |
347 | 348 |
348 SYS$QIOW (0, fileno (TTY_INPUT (CURTTY())), IO$_SENSEMODE, &sg, 0, 0, | 349 SYS$QIOW (0, fileno (TTY_INPUT (tty)), IO$_SENSEMODE, &sg, 0, 0, |
349 &sg.class, 12, 0, 0, 0, 0 ); | 350 &sg.class, 12, 0, 0, 0, 0 ); |
350 emacs_ospeed = sg.xmit_baud; | 351 emacs_ospeed = sg.xmit_baud; |
351 #else /* not VMS */ | 352 #else /* not VMS */ |
352 #ifdef HAVE_TERMIOS | 353 #ifdef HAVE_TERMIOS |
353 struct termios sg; | 354 struct termios sg; |
354 | 355 |
355 sg.c_cflag = B9600; | 356 sg.c_cflag = B9600; |
356 tcgetattr (fileno (TTY_INPUT (CURTTY())), &sg); | 357 tcgetattr (fileno (TTY_INPUT (tty)), &sg); |
357 emacs_ospeed = cfgetospeed (&sg); | 358 emacs_ospeed = cfgetospeed (&sg); |
358 #if defined (USE_GETOBAUD) && defined (getobaud) | 359 #if defined (USE_GETOBAUD) && defined (getobaud) |
359 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */ | 360 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */ |
360 if (emacs_ospeed == 0) | 361 if (emacs_ospeed == 0) |
361 emacs_ospeed = getobaud (sg.c_cflag); | 362 emacs_ospeed = getobaud (sg.c_cflag); |
364 #ifdef HAVE_TERMIO | 365 #ifdef HAVE_TERMIO |
365 struct termio sg; | 366 struct termio sg; |
366 | 367 |
367 sg.c_cflag = B9600; | 368 sg.c_cflag = B9600; |
368 #ifdef HAVE_TCATTR | 369 #ifdef HAVE_TCATTR |
369 tcgetattr (fileno (TTY_INPUT (CURTTY())), &sg); | 370 tcgetattr (fileno (TTY_INPUT (tty)), &sg); |
370 #else | 371 #else |
371 ioctl (fileno (TTY_INPUT (CURTTY())), TCGETA, &sg); | 372 ioctl (fileno (TTY_INPUT (tty)), TCGETA, &sg); |
372 #endif | 373 #endif |
373 emacs_ospeed = sg.c_cflag & CBAUD; | 374 emacs_ospeed = sg.c_cflag & CBAUD; |
374 #else /* neither VMS nor TERMIOS nor TERMIO */ | 375 #else /* neither VMS nor TERMIOS nor TERMIO */ |
375 struct sgttyb sg; | 376 struct sgttyb sg; |
376 | 377 |
377 sg.sg_ospeed = B9600; | 378 sg.sg_ospeed = B9600; |
378 if (ioctl (fileno (TTY_INPUT (CURTTY())), TIOCGETP, &sg) < 0) | 379 if (ioctl (fileno (TTY_INPUT (tty)), TIOCGETP, &sg) < 0) |
379 abort (); | 380 abort (); |
380 emacs_ospeed = sg.sg_ospeed; | 381 emacs_ospeed = sg.sg_ospeed; |
381 #endif /* not HAVE_TERMIO */ | 382 #endif /* not HAVE_TERMIO */ |
382 #endif /* not HAVE_TERMIOS */ | 383 #endif /* not HAVE_TERMIOS */ |
383 #endif /* not VMS */ | 384 #endif /* not VMS */ |
647 | 648 |
648 EMACS_SET_TTY (out, &s, 0); | 649 EMACS_SET_TTY (out, &s, 0); |
649 | 650 |
650 #ifdef BSD4_1 | 651 #ifdef BSD4_1 |
651 if (interrupt_input) | 652 if (interrupt_input) |
652 reset_sigio (); | 653 reset_sigio (0); |
653 #endif /* BSD4_1 */ | 654 #endif /* BSD4_1 */ |
654 #ifdef RTU | 655 #ifdef RTU |
655 { | 656 { |
656 int zero = 0; | 657 int zero = 0; |
657 ioctl (out, FIOASYNC, &zero); | 658 ioctl (out, FIOASYNC, &zero); |
913 void | 914 void |
914 init_sigio (fd) | 915 init_sigio (fd) |
915 int fd; | 916 int fd; |
916 { | 917 { |
917 #ifdef FASYNC | 918 #ifdef FASYNC |
919 /* XXX What if we get called with more than one fds? */ | |
918 old_fcntl_flags = fcntl (fd, F_GETFL, 0) & ~FASYNC; | 920 old_fcntl_flags = fcntl (fd, F_GETFL, 0) & ~FASYNC; |
919 fcntl (fd, F_SETFL, old_fcntl_flags | FASYNC); | 921 fcntl (fd, F_SETFL, old_fcntl_flags | FASYNC); |
920 #endif | 922 #endif |
921 interrupts_deferred = 0; | 923 interrupts_deferred = 0; |
922 } | 924 } |
923 | 925 |
924 void | 926 void |
925 reset_sigio () | 927 reset_sigio (fd) |
926 { | 928 int fd; |
927 unrequest_sigio (); | 929 { |
930 fcntl (fd, F_SETFL, old_fcntl_flags); | |
928 } | 931 } |
929 | 932 |
930 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */ | 933 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */ |
931 | 934 |
932 void | 935 void |
936 return; | 939 return; |
937 | 940 |
938 #ifdef SIGWINCH | 941 #ifdef SIGWINCH |
939 sigunblock (sigmask (SIGWINCH)); | 942 sigunblock (sigmask (SIGWINCH)); |
940 #endif | 943 #endif |
941 fcntl (fileno (TTY_INPUT (CURTTY())), F_SETFL, old_fcntl_flags | FASYNC); | 944 sigunblock (sigmask (SIGIO)); |
942 | 945 |
943 interrupts_deferred = 0; | 946 interrupts_deferred = 0; |
944 } | 947 } |
945 | 948 |
946 void | 949 void |
947 unrequest_sigio () | 950 unrequest_sigio (void) |
948 { | 951 { |
949 if (read_socket_hook) | 952 if (read_socket_hook) |
950 return; | 953 return; |
951 | 954 |
952 #ifdef SIGWINCH | 955 #ifdef SIGWINCH |
953 sigblock (sigmask (SIGWINCH)); | 956 sigblock (sigmask (SIGWINCH)); |
954 #endif | 957 #endif |
955 fcntl (fileno (TTY_INPUT (CURTTY())), F_SETFL, old_fcntl_flags); | 958 sigblock (sigmask (SIGIO)); |
956 interrupts_deferred = 1; | 959 interrupts_deferred = 1; |
957 } | 960 } |
958 | 961 |
959 #else /* no FASYNC */ | 962 #else /* no FASYNC */ |
960 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */ | 963 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */ |
965 int on = 1; | 968 int on = 1; |
966 | 969 |
967 if (read_socket_hook) | 970 if (read_socket_hook) |
968 return; | 971 return; |
969 | 972 |
970 ioctl (fileno (TTY_INPUT (CURTTY())), FIOASYNC, &on); | 973 /* XXX CURTTY() is bogus here. */ |
974 ioctl (fileno (TTY_INPUT (CURTTY ())), FIOASYNC, &on); | |
971 interrupts_deferred = 0; | 975 interrupts_deferred = 0; |
972 } | 976 } |
973 | 977 |
974 void | 978 void |
975 unrequest_sigio () | 979 unrequest_sigio (struct tty_output *tty) |
976 { | 980 { |
977 int off = 0; | 981 int off = 0; |
978 | 982 |
979 if (read_socket_hook) | 983 if (read_socket_hook) |
980 return; | 984 return; |
981 | 985 |
982 ioctl (fileno (TTY_INPUT (CURTTY())), FIOASYNC, &off); | 986 /* XXX CURTTY() is bogus here. */ |
987 ioctl (fileno (TTY_INPUT (CURTTY ())), FIOASYNC, &off); | |
983 interrupts_deferred = 1; | 988 interrupts_deferred = 1; |
984 } | 989 } |
985 | 990 |
986 #else /* not FASYNC, not STRIDE */ | 991 #else /* not FASYNC, not STRIDE */ |
987 | 992 |
998 if (read_socket_hook) | 1003 if (read_socket_hook) |
999 return; | 1004 return; |
1000 | 1005 |
1001 sigemptyset (&st); | 1006 sigemptyset (&st); |
1002 sigaddset (&st, SIGIO); | 1007 sigaddset (&st, SIGIO); |
1003 ioctl (fileno (TTY_INPUT (CURTTY())), FIOASYNC, &on); | 1008 ioctl (0, FIOASYNC, &on); /* XXX This fails for multiple ttys. */ |
1004 interrupts_deferred = 0; | 1009 interrupts_deferred = 0; |
1005 sigprocmask (SIG_UNBLOCK, &st, (sigset_t *)0); | 1010 sigprocmask (SIG_UNBLOCK, &st, (sigset_t *)0); |
1006 } | 1011 } |
1007 | 1012 |
1008 void | 1013 void |
1011 int off = 0; | 1016 int off = 0; |
1012 | 1017 |
1013 if (read_socket_hook) | 1018 if (read_socket_hook) |
1014 return; | 1019 return; |
1015 | 1020 |
1016 ioctl (fileno (TTY_INPUT (CURTTY())), FIOASYNC, &off); | 1021 ioctl (0, FIOASYNC, &off); /* XXX This fails for multiple ttys. */ |
1017 interrupts_deferred = 1; | 1022 interrupts_deferred = 1; |
1018 } | 1023 } |
1019 | 1024 |
1020 #else /* ! _CX_UX */ | 1025 #else /* ! _CX_UX */ |
1021 #ifndef MSDOS | 1026 #ifndef MSDOS |
1726 #else | 1731 #else |
1727 #ifdef VMS | 1732 #ifdef VMS |
1728 | 1733 |
1729 struct sensemode tty; | 1734 struct sensemode tty; |
1730 | 1735 |
1731 SYS$QIOW (0, fileno (TTY_INPUT (CURTTY())), IO$_SENSEMODE, &tty, 0, 0, | 1736 SYS$QIOW (0, fileno (TTY_INPUT (tty_out)), IO$_SENSEMODE, &tty, 0, 0, |
1732 &tty.class, 12, 0, 0, 0, 0); | 1737 &tty.class, 12, 0, 0, 0, 0); |
1733 *widthp = tty.scr_wid; | 1738 *widthp = tty.scr_wid; |
1734 *heightp = tty.scr_len; | 1739 *heightp = tty.scr_len; |
1735 | 1740 |
1736 #else | 1741 #else |
1793 reset_sys_modes (tty); | 1798 reset_sys_modes (tty); |
1794 tty = tty->next; | 1799 tty = tty->next; |
1795 } | 1800 } |
1796 } | 1801 } |
1797 | 1802 |
1798 /* Prepare the terminal for exiting Emacs; move the cursor to the | 1803 /* Prepare the terminal for closing it; move the cursor to the |
1799 bottom of the frame, turn off interrupt-driven I/O, etc. */ | 1804 bottom of the frame, turn off interrupt-driven I/O, etc. */ |
1800 void | 1805 void |
1801 reset_sys_modes (tty_out) | 1806 reset_sys_modes (tty_out) |
1802 struct tty_output *tty_out; | 1807 struct tty_output *tty_out; |
1803 { | 1808 { |
1804 struct frame *sf; | |
1805 | |
1806 if (noninteractive) | 1809 if (noninteractive) |
1807 { | 1810 { |
1808 fflush (stdout); | 1811 fflush (stdout); |
1809 return; | 1812 return; |
1810 } | 1813 } |
1820 || read_socket_hook | 1823 || read_socket_hook |
1821 #endif | 1824 #endif |
1822 ) | 1825 ) |
1823 return; | 1826 return; |
1824 #endif | 1827 #endif |
1825 sf = SELECTED_FRAME (); | 1828 cmgoto (tty_out, FrameRows (tty_out) - 1, 0); |
1826 cursor_to (FRAME_LINES (sf) - 1, 0); | 1829 tty_clear_end_of_line (tty_out, FrameCols (tty_out)); |
1827 clear_end_of_line (FRAME_COLS (sf)); | 1830 cmgoto (tty_out, FrameRows (tty_out) - 1, 0); |
1828 /* clear_end_of_line may move the cursor */ | |
1829 cursor_to (FRAME_LINES (sf) - 1, 0); | |
1830 #if defined (IBMR2AIX) && defined (AIXHFT) | 1831 #if defined (IBMR2AIX) && defined (AIXHFT) |
1831 { | 1832 { |
1832 /* HFT devices normally use ^J as a LF/CR. We forced it to | 1833 /* HFT devices normally use ^J as a LF/CR. We forced it to |
1833 do the LF only. Now, we need to reset it. */ | 1834 do the LF only. Now, we need to reset it. */ |
1834 struct termio tty; | 1835 struct termio tty; |
1850 #ifdef F_SETFL | 1851 #ifdef F_SETFL |
1851 #ifndef F_SETOWN_BUG | 1852 #ifndef F_SETOWN_BUG |
1852 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */ | 1853 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */ |
1853 if (interrupt_input) | 1854 if (interrupt_input) |
1854 { | 1855 { |
1855 reset_sigio (); | 1856 reset_sigio (tty_out); |
1856 fcntl (fileno (TTY_INPUT (tty_out)), F_SETOWN, old_fcntl_owner); | 1857 fcntl (fileno (TTY_INPUT (tty_out)), F_SETOWN, old_fcntl_owner); |
1857 } | 1858 } |
1858 #endif /* F_SETOWN */ | 1859 #endif /* F_SETOWN */ |
1859 #endif /* F_SETOWN_BUG */ | 1860 #endif /* F_SETOWN_BUG */ |
1860 #ifdef O_NDELAY | 1861 #ifdef O_NDELAY |
1862 fcntl (fileno (TTY_INPUT (tty_out)), F_GETFL, 0) & ~O_NDELAY); | 1863 fcntl (fileno (TTY_INPUT (tty_out)), F_GETFL, 0) & ~O_NDELAY); |
1863 #endif | 1864 #endif |
1864 #endif /* F_SETFL */ | 1865 #endif /* F_SETFL */ |
1865 #ifdef BSD4_1 | 1866 #ifdef BSD4_1 |
1866 if (interrupt_input) | 1867 if (interrupt_input) |
1867 reset_sigio (); | 1868 reset_sigio (tty_out); |
1868 #endif /* BSD4_1 */ | 1869 #endif /* BSD4_1 */ |
1869 | 1870 |
1870 if (tty_out->old_tty) | 1871 if (tty_out->old_tty) |
1871 while (EMACS_SET_TTY (fileno (TTY_INPUT (tty_out)), | 1872 while (EMACS_SET_TTY (fileno (TTY_INPUT (tty_out)), |
1872 tty_out->old_tty, 0) < 0 && errno == EINTR) | 1873 tty_out->old_tty, 0) < 0 && errno == EINTR) |
2168 int fd; | 2169 int fd; |
2169 { | 2170 { |
2170 request_sigio (); | 2171 request_sigio (); |
2171 } | 2172 } |
2172 | 2173 |
2173 reset_sigio () | 2174 reset_sigio (fd) |
2175 int fd; | |
2174 { | 2176 { |
2175 unrequest_sigio (); | 2177 unrequest_sigio (); |
2176 } | 2178 } |
2177 | 2179 |
2178 void | 2180 void |
2718 lmode = LINTRUP | lmode; | 2720 lmode = LINTRUP | lmode; |
2719 ioctl (fd, TIOCLSET, &lmode); | 2721 ioctl (fd, TIOCLSET, &lmode); |
2720 } | 2722 } |
2721 | 2723 |
2722 void | 2724 void |
2723 reset_sigio () | 2725 reset_sigio (fd) |
2726 int fd; | |
2724 { | 2727 { |
2725 if (noninteractive) | 2728 if (noninteractive) |
2726 return; | 2729 return; |
2727 lmode = ~LINTRUP & lmode; | 2730 lmode = ~LINTRUP & lmode; |
2728 ioctl (0, TIOCLSET, &lmode); | 2731 ioctl (fd, TIOCLSET, &lmode); |
2729 } | 2732 } |
2730 | 2733 |
2731 void | 2734 void |
2732 request_sigio () | 2735 request_sigio () |
2733 { | 2736 { |
3171 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is | 3174 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is |
3172 to force a call on the debugger from within the image. */ | 3175 to force a call on the debugger from within the image. */ |
3173 #undef abort | 3176 #undef abort |
3174 sys_abort () | 3177 sys_abort () |
3175 { | 3178 { |
3176 reset_sys_modes (); | 3179 reset_all_sys_modes (); |
3177 LIB$SIGNAL (SS$_DEBUG); | 3180 LIB$SIGNAL (SS$_DEBUG); |
3178 } | 3181 } |
3179 #endif /* abort */ | 3182 #endif /* abort */ |
3180 #endif /* VMS */ | 3183 #endif /* VMS */ |
3181 | 3184 |