for (i = 0; i < KBD_BUFFER_SIZE; i++)
EVENT_INIT (buf[i]);
- for (d = display_list; d; d = d->next_display)
+ d = display_list;
+ while (d)
{
+ struct display *next = d->next_display;
+
if (d->read_socket_hook)
/* No need for FIONREAD or fcntl; just say don't wait. */
nread = (*d->read_socket_hook) (d, buf, KBD_BUFFER_SIZE, expected);
- if (nread > 0)
- break;
+ if (nread == -2)
+ {
+ /* The display device terminated; it should be closed. */
+
+ /* Kill Emacs if this was our last display. */
+ if (! display_list->next_display)
+ kill (getpid (), SIGHUP);
+
+ /* XXX Is calling delete_display safe here? It calls Fdelete_frame. */
+ if (d->delete_display_hook)
+ (*d->delete_display_hook) (d);
+ else
+ delete_display (d);
+ }
+ else if (nread > 0)
+ {
+ /* We've got input. */
+ break;
+ }
+
+ d = next;
}
/* Scan the chars for C-g and store them in kbd_buffer. */
Note that each terminal device has its own `struct display' object,
and so this function is called once for each individual termcap
display. The first parameter indicates which device to read from. */
+
int
tty_read_avail_input (struct display *display,
struct input_event *buf,
if (ioctl (fileno (TTY_INPUT (tty)), FIONREAD, &n_to_read) < 0)
{
if (! noninteractive)
- {
- delete_tty (tty); /* XXX I wonder if this is safe here. */
-
- /* Formerly simply reported no input, but that sometimes led to
- a failure of Emacs to terminate.
- SIGHUP seems appropriate if we can't reach the terminal. */
- /* ??? Is it really right to send the signal just to this process
- rather than to the whole process group?
- Perhaps on systems with FIONREAD Emacs is alone in its group. */
- /* It appears to be the case, see narrow_foreground_group. */
- if (! tty_list->next)
- kill (getpid (), SIGHUP); /* This was the last terminal. */
- }
+ return -2; /* Close this display. */
else
- {
- n_to_read = 0;
- }
+ n_to_read = 0;
}
if (n_to_read == 0)
return 0;
Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
if (nread == -1 && errno == EIO)
{
- if (! tty_list->next)
- kill (0, SIGHUP); /* This was the last terminal. */
- else
- delete_tty (tty); /* XXX I wonder if this is safe here. */
+ return -2; /* Close this display. */
}
#if defined (AIX) && (! defined (aix386) && defined (_BSD))
/* The kernel sometimes fails to deliver SIGHUP for ptys.
and that causes a value other than 0 when there is no input. */
if (nread == 0)
{
- if (! tty_list->next)
- kill (0, SIGHUP); /* This was the last terminal. */
- else
- delete_tty (tty); /* XXX I wonder if this is safe here. */
+ return -2; /* Close this display. */
}
#endif
}
input_available_clear_time = 0;
}
-/* This routine is called at interrupt level in response to C-g.
-
- If interrupt_input, this is the handler for SIGINT. Otherwise, it
- is called from kbd_buffer_store_event, in handling SIGIO or
- SIGTINT.
-
- If `waiting_for_input' is non zero, then unless `echoing' is
- nonzero, immediately throw back to read_char.
-
- Otherwise it sets the Lisp variable quit-flag not-nil. This causes
- eval to throw, when it gets a chance. If quit-flag is already
- non-nil, it stops the job right away.
+/* The SIGINT handler.
- XXX This comment needs to be updated. */
+ If we have a frame on the controlling tty, the SIGINT was generated
+ by C-g, so we call handle_interrupt. Otherwise, the handler kills
+ Emacs. */
static SIGTYPE
interrupt_signal (signalnum) /* If we don't have an argument, */
internal_last_event_frame = display->display_info.tty->top_frame;
handle_interrupt ();
-
}
errno = old_errno;
}
-/* C-g processing, signal independent code.
+/* This routine is called at interrupt level in response to C-g.
+
+ It is called from the SIGINT handler or kbd_buffer_store_event.
+
+ If `waiting_for_input' is non zero, then unless `echoing' is
+ nonzero, immediately throw back to read_char.
+
+ Otherwise it sets the Lisp variable quit-flag not-nil. This causes
+ eval to throw, when it gets a chance. If quit-flag is already
+ non-nil, it stops the job right away. */
- XXX Expand this comment. */
static void
handle_interrupt ()
{