[PATCH 2/5] [terminal] keep track of terminal raw/cooked state

Scott James Remnant scott at ubuntu.com
Thu Mar 18 14:32:29 PDT 2010


Instead of setting the terminal to unbuffered (raw) mode on every
write, keep track of whether it's unbuffered or not at the points
we open and close the terminal.

Deactivate already takes care to set back into buffered mode;
otherwise we can end up resetting the terminal mode under X causing
Enter to send X SIGQUIT.

(Even with the improved terminal setting code)
---
 src/libply-splash-core/ply-terminal.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/libply-splash-core/ply-terminal.c b/src/libply-splash-core/ply-terminal.c
index 0f70bf7..3487387 100644
--- a/src/libply-splash-core/ply-terminal.c
+++ b/src/libply-splash-core/ply-terminal.c
@@ -81,6 +81,7 @@ struct _ply_terminal
   uint32_t supports_text_color : 1;
   uint32_t is_open : 1;
   uint32_t is_active : 1;
+  uint32_t is_unbuffered : 1;
   uint32_t is_watching_for_vt_changes : 1;
   uint32_t should_ignore_mode_changes : 1;
 };
@@ -182,6 +183,8 @@ ply_terminal_set_unbuffered_input (ply_terminal_t *terminal)
   if (tcsetattr (terminal->fd, TCSAFLUSH, &term_attributes) != 0)
     return false;
 
+  terminal->is_unbuffered = true;
+
   return true;
 }
 
@@ -190,13 +193,20 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
 {
   struct termios term_attributes;
 
+  if (!terminal->is_unbuffered)
+    return true;
+
   tcgetattr (terminal->fd, &term_attributes);
 
   /* If someone already messed with the terminal settings,
    * and they seem good enough, bail
    */
   if (term_attributes.c_lflag & ICANON)
-    return true;
+    {
+      terminal->is_unbuffered = false;
+
+      return true;
+    }
 
   /* If we don't know the original term attributes, or they were originally sucky,
    * then invent some that are probably good enough.
@@ -210,12 +220,16 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
       if (tcsetattr (terminal->fd, TCSAFLUSH, &term_attributes) != 0)
         return false;
 
+      terminal->is_unbuffered = false;
+
       return true;
     }
 
   if (tcsetattr (terminal->fd, TCSAFLUSH, &terminal->original_term_attributes) != 0)
     return false;
 
+  terminal->is_unbuffered = false;
+
   return true;
 }
 
@@ -230,8 +244,6 @@ ply_terminal_write (ply_terminal_t *terminal,
   assert (terminal != NULL);
   assert (format != NULL);
 
-  ply_terminal_set_unbuffered_input (terminal);
-
   string = NULL;
   va_start (args, format);
   vasprintf (&string, format, args);
-- 
1.7.0



More information about the plymouth mailing list