]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[terminal] Lock terminal settings
authorRay Strode <rstrode@redhat.com>
Wed, 14 Apr 2010 19:04:23 +0000 (15:04 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 14 Apr 2010 19:09:23 +0000 (15:09 -0400)
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

e9a22723da7c9400d25aeff2625651b3d03be43f

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

src/libply-splash-core/ply-terminal.c

index 3e90dec53954a8111d3e2c02838aaa6bc0c7977e..8b099b872060a73ec105ac399eb91d3fde4afdef 100644 (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,