[terminal] Lock terminal settings

From time to time, various external programs
will muck with the tty we're using and make
the users password for encrypted disks show
up, make the enter key not work, etc.

We used to work around this by resetting the
tty the way we like it everytime we write the
screen.

We no longer do that after commit

e9a22723da

Instead of changing it every time, it's probably
better to just prevent other programs from messing
up the settings in the first place.

This commit locks the terminal so if those programs
try to change the settings, they fail.

A better long term solution might be to get user input
/dev/input instead of the tty
This commit is contained in:
Ray Strode 2010-04-14 15:04:23 -04:00
parent 4c9b12fd2e
commit 559a1b2ff4

View file

@ -61,6 +61,7 @@ struct _ply_terminal
ply_event_loop_t *loop;
struct termios original_term_attributes;
struct termios original_locked_term_attributes;
char *name;
int fd;
@ -79,6 +80,7 @@ struct _ply_terminal
int number_of_columns;
uint32_t original_term_attributes_saved : 1;
uint32_t original_locked_term_attributes_saved : 1;
uint32_t supports_text_color : 1;
uint32_t is_open : 1;
uint32_t is_active : 1;
@ -168,6 +170,7 @@ bool
ply_terminal_set_unbuffered_input (ply_terminal_t *terminal)
{
struct termios term_attributes;
struct termios locked_term_attributes;
tcgetattr (terminal->fd, &term_attributes);
@ -185,6 +188,18 @@ ply_terminal_set_unbuffered_input (ply_terminal_t *terminal)
if (tcsetattr (terminal->fd, TCSANOW, &term_attributes) != 0)
return false;
if (ioctl (terminal->fd, TIOCGLCKTRMIOS, &locked_term_attributes) == 0)
{
terminal->original_locked_term_attributes = locked_term_attributes;
terminal->original_locked_term_attributes_saved = true;
memset (&locked_term_attributes, 0xff, sizeof (locked_term_attributes));
if (ioctl (terminal->fd, TIOCSLCKTRMIOS, &locked_term_attributes) < 0)
{
ply_trace ("couldn't lock terminal settings: %m");
}
}
terminal->is_unbuffered = true;
return true;
@ -198,6 +213,16 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
if (!terminal->is_unbuffered)
return true;
if (terminal->original_locked_term_attributes_saved)
{
if (ioctl (terminal->fd, TIOCSLCKTRMIOS,
&terminal->original_locked_term_attributes) < 0)
{
ply_trace ("couldn't unlock terminal settings: %m");
}
terminal->original_locked_term_attributes_saved = false;
}
tcgetattr (terminal->fd, &term_attributes);
/* If someone already messed with the terminal settings,