Blob Blame History Raw
From 559a1b2ff4ad8f21a0a28bebe751774ee9e4a4df Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 14 Apr 2010 15:04:23 -0400
Subject: [PATCH] [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

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 |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/libply-splash-core/ply-terminal.c b/src/libply-splash-core/ply-terminal.c
index 3e90dec..8b099b8 100644
--- a/src/libply-splash-core/ply-terminal.c
+++ b/src/libply-splash-core/ply-terminal.c
@@ -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,
-- 
1.6.5.2

From 8c390bea97ccd2c0f74f63fd90d549dd4f488651 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 7 May 2010 14:49:09 -0400
Subject: [PATCH] [terminal] Don't stomp over original tty lock settings

We were repetedly saving over the original tty lock settings,
causing the tty to stay locked after boot up.
---
 src/libply-splash-core/ply-terminal.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/libply-splash-core/ply-terminal.c b/src/libply-splash-core/ply-terminal.c
index f71f25a..ff59d71 100644
--- a/src/libply-splash-core/ply-terminal.c
+++ b/src/libply-splash-core/ply-terminal.c
@@ -188,7 +188,8 @@ 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)
+  if (!terminal->original_locked_term_attributes_saved &&
+      ioctl (terminal->fd, TIOCGLCKTRMIOS, &locked_term_attributes) == 0)
     {
       terminal->original_locked_term_attributes = locked_term_attributes;
       terminal->original_locked_term_attributes_saved = true;
-- 
1.6.5.2