1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-28 01:35:32 +00:00

terminal: Kill the ESC timer when blocking the terminal.

Otherwise, the timeout could cause ELinks to resume reading from
the terminal device while another process is still using it.
This actually happened in a test.

On entry to some functions that could resume reading from the device,
assert that the terminal has not been blocked.
This commit is contained in:
Kalle Olavi Niemitalo 2006-07-28 15:48:57 +03:00 committed by Miciah Dashiel Butler Masters
parent 671cbb48e6
commit 539f756438

View File

@ -373,6 +373,8 @@ block_itrm(int fd)
ditrm->blocked = 1;
block_stdin();
kill_timer(&ditrm->timer);
ditrm->in.queue.len = 0;
unhandle_terminal_resize(ditrm->in.ctl);
send_done_sequence(ditrm->out.std, ditrm->altscreen);
tcsetattr(ditrm->in.ctl, TCSANOW, &ditrm->t);
@ -626,14 +628,15 @@ kbd_timeout(struct itrm *itrm)
itrm->timer = TIMER_ID_UNDEF;
assertm(itrm->in.queue.len, "timeout on empty queue");
assert(!itrm->blocked); /* block_itrm should have killed itrm->timer */
if_assert_failed return;
if (can_read(itrm->in.std)) {
in_kbd(itrm);
return;
}
assertm(itrm->in.queue.len, "timeout on empty queue");
if_assert_failed return;
set_kbd_term_event(&ev, KBD_ESC, KBD_MOD_NONE);
itrm_queue_event(itrm, (char *) &ev, sizeof(ev));
@ -839,7 +842,7 @@ set_kbd_event(struct term_event *ev, int key, int modifier)
* Return the number of bytes removed from itrm->in.queue; at least 0.
* If this function leaves the queue not full, it also reenables reading
* from itrm->in.std. (Because it does not add to the queue, it never
* need disable reading.) */
* need disable reading.) On entry, the itrm must not be blocked. */
static int
process_queue(struct itrm *itrm)
{
@ -847,6 +850,8 @@ process_queue(struct itrm *itrm)
int el = 0;
if (!itrm->in.queue.len) goto end;
assert(!itrm->blocked);
if_assert_failed return 0; /* unlike goto, don't enable reading */
set_kbd_term_event(&ev, KBD_UNDEF, KBD_MOD_NONE);