comparison src/keyboard.c @ 83021:32bf8e7cc0c2

Fixed tty faces during combo sessions. Plus other assorted bugfixes. lisp/startup.el (command-line): Always call tty-register-default-colors. src/dispextern.h (delete_tty): Added missing prototype. src/keyboard.c (read_avail_input): Close display gracefully if needed. Kill Emacs if the last display is to be closed. (tty_read_avail_input): Don't call delete_tty and don't signal hangup here; return -2 instead to indicate the non-transient failure to read_avail_input. src/term.c (delete_tty): Removed superflous wiping of the deleted frames' output_data field. (delete_display): Check for and close live frames that are still on the display. src/termhooks.h (read_socket_hook, delete_display_hook): Added detailed comment. src/xfaces.c (realize_face): Create a dummy face for the initial frame. (Reported by Robert J. Chassell (bob at rattlenake dot com).) git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-61
author Karoly Lorentey <lorentey@elte.hu>
date Fri, 23 Jan 2004 21:48:58 +0000
parents 82c3b4da43ca
children c66ebcc29777
comparison
equal deleted inserted replaced
83020:d617fe346b2b 83021:32bf8e7cc0c2
6578 int nread = 0; 6578 int nread = 0;
6579 6579
6580 for (i = 0; i < KBD_BUFFER_SIZE; i++) 6580 for (i = 0; i < KBD_BUFFER_SIZE; i++)
6581 EVENT_INIT (buf[i]); 6581 EVENT_INIT (buf[i]);
6582 6582
6583 for (d = display_list; d; d = d->next_display) 6583 d = display_list;
6584 { 6584 while (d)
6585 {
6586 struct display *next = d->next_display;
6587
6585 if (d->read_socket_hook) 6588 if (d->read_socket_hook)
6586 /* No need for FIONREAD or fcntl; just say don't wait. */ 6589 /* No need for FIONREAD or fcntl; just say don't wait. */
6587 nread = (*d->read_socket_hook) (d, buf, KBD_BUFFER_SIZE, expected); 6590 nread = (*d->read_socket_hook) (d, buf, KBD_BUFFER_SIZE, expected);
6588 6591
6589 if (nread > 0) 6592 if (nread == -2)
6590 break; 6593 {
6594 /* The display device terminated; it should be closed. */
6595
6596 /* Kill Emacs if this was our last display. */
6597 if (! display_list->next_display)
6598 kill (getpid (), SIGHUP);
6599
6600 /* XXX Is calling delete_display safe here? It calls Fdelete_frame. */
6601 if (d->delete_display_hook)
6602 (*d->delete_display_hook) (d);
6603 else
6604 delete_display (d);
6605 }
6606 else if (nread > 0)
6607 {
6608 /* We've got input. */
6609 break;
6610 }
6611
6612 d = next;
6591 } 6613 }
6592 6614
6593 /* Scan the chars for C-g and store them in kbd_buffer. */ 6615 /* Scan the chars for C-g and store them in kbd_buffer. */
6594 for (i = 0; i < nread; i++) 6616 for (i = 0; i < nread; i++)
6595 { 6617 {
6607 /* This is the tty way of reading available input. 6629 /* This is the tty way of reading available input.
6608 6630
6609 Note that each terminal device has its own `struct display' object, 6631 Note that each terminal device has its own `struct display' object,
6610 and so this function is called once for each individual termcap 6632 and so this function is called once for each individual termcap
6611 display. The first parameter indicates which device to read from. */ 6633 display. The first parameter indicates which device to read from. */
6634
6612 int 6635 int
6613 tty_read_avail_input (struct display *display, 6636 tty_read_avail_input (struct display *display,
6614 struct input_event *buf, 6637 struct input_event *buf,
6615 int numchars, int expected) 6638 int numchars, int expected)
6616 { 6639 {
6648 #ifdef FIONREAD 6671 #ifdef FIONREAD
6649 /* Find out how much input is available. */ 6672 /* Find out how much input is available. */
6650 if (ioctl (fileno (TTY_INPUT (tty)), FIONREAD, &n_to_read) < 0) 6673 if (ioctl (fileno (TTY_INPUT (tty)), FIONREAD, &n_to_read) < 0)
6651 { 6674 {
6652 if (! noninteractive) 6675 if (! noninteractive)
6653 { 6676 return -2; /* Close this display. */
6654 delete_tty (tty); /* XXX I wonder if this is safe here. */
6655
6656 /* Formerly simply reported no input, but that sometimes led to
6657 a failure of Emacs to terminate.
6658 SIGHUP seems appropriate if we can't reach the terminal. */
6659 /* ??? Is it really right to send the signal just to this process
6660 rather than to the whole process group?
6661 Perhaps on systems with FIONREAD Emacs is alone in its group. */
6662 /* It appears to be the case, see narrow_foreground_group. */
6663 if (! tty_list->next)
6664 kill (getpid (), SIGHUP); /* This was the last terminal. */
6665 }
6666 else 6677 else
6667 { 6678 n_to_read = 0;
6668 n_to_read = 0;
6669 }
6670 } 6679 }
6671 if (n_to_read == 0) 6680 if (n_to_read == 0)
6672 return 0; 6681 return 0;
6673 if (n_to_read > sizeof cbuf) 6682 if (n_to_read > sizeof cbuf)
6674 n_to_read = sizeof cbuf; 6683 n_to_read = sizeof cbuf;
6692 this part standard and returns -1 from read (0) with errno==EIO 6701 this part standard and returns -1 from read (0) with errno==EIO
6693 when the control tty is taken away. 6702 when the control tty is taken away.
6694 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ 6703 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6695 if (nread == -1 && errno == EIO) 6704 if (nread == -1 && errno == EIO)
6696 { 6705 {
6697 if (! tty_list->next) 6706 return -2; /* Close this display. */
6698 kill (0, SIGHUP); /* This was the last terminal. */
6699 else
6700 delete_tty (tty); /* XXX I wonder if this is safe here. */
6701 } 6707 }
6702 #if defined (AIX) && (! defined (aix386) && defined (_BSD)) 6708 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
6703 /* The kernel sometimes fails to deliver SIGHUP for ptys. 6709 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6704 This looks incorrect, but it isn't, because _BSD causes 6710 This looks incorrect, but it isn't, because _BSD causes
6705 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 6711 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6706 and that causes a value other than 0 when there is no input. */ 6712 and that causes a value other than 0 when there is no input. */
6707 if (nread == 0) 6713 if (nread == 0)
6708 { 6714 {
6709 if (! tty_list->next) 6715 return -2; /* Close this display. */
6710 kill (0, SIGHUP); /* This was the last terminal. */
6711 else
6712 delete_tty (tty); /* XXX I wonder if this is safe here. */
6713 } 6716 }
6714 #endif 6717 #endif
6715 } 6718 }
6716 while ( 6719 while (
6717 /* We used to retry the read if it was interrupted. 6720 /* We used to retry the read if it was interrupted.