Michal Schmidt e1f787
From e5740fa36d79ecd9d4aaee5f757c1829be232978 Mon Sep 17 00:00:00 2001
Michal Schmidt e1f787
From: Michal Schmidt <mschmidt@redhat.com>
Michal Schmidt e1f787
Date: Sun, 29 Jan 2012 21:55:51 +0100
Michal Schmidt e1f787
Subject: [PATCH] main: don't force text mode in console_setup()
Michal Schmidt e1f787
Michal Schmidt e1f787
When systemd starts, plymouth may be already displaying progress
Michal Schmidt e1f787
graphically. Do not switch the console to text mode at that time.
Michal Schmidt e1f787
All other users of reset_terminal_fd() do the switch as before.
Michal Schmidt e1f787
Michal Schmidt e1f787
This avoids a graphical glitch with plymouth, especially visible with
Michal Schmidt e1f787
vesafb, but could be also seen as a sub-second blink with radeon.
Michal Schmidt e1f787
Michal Schmidt e1f787
https://bugzilla.redhat.com/show_bug.cgi?id=785548
Michal Schmidt e1f787
(cherry picked from commit 512947d46f9fd7daf74c059ac8548cc98b294807)
Michal Schmidt e1f787
---
Michal Schmidt e1f787
 src/main.c |    8 ++++++--
Michal Schmidt e1f787
 src/util.c |   10 ++++++----
Michal Schmidt e1f787
 src/util.h |    2 +-
Michal Schmidt e1f787
 3 files changed, 13 insertions(+), 7 deletions(-)
Michal Schmidt e1f787
Michal Schmidt e1f787
diff --git a/src/main.c b/src/main.c
Michal Schmidt e1f787
index cdf32bf..87e0f32 100644
Michal Schmidt e1f787
--- a/src/main.c
Michal Schmidt e1f787
+++ b/src/main.c
Michal Schmidt e1f787
@@ -200,12 +200,16 @@ static int console_setup(bool do_reset) {
Michal Schmidt e1f787
         if (!do_reset)
Michal Schmidt e1f787
                 return 0;
Michal Schmidt e1f787
 
Michal Schmidt e1f787
-        if ((tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC)) < 0) {
Michal Schmidt e1f787
+        tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
Michal Schmidt e1f787
+        if (tty_fd < 0) {
Michal Schmidt e1f787
                 log_error("Failed to open /dev/console: %s", strerror(-tty_fd));
Michal Schmidt e1f787
                 return -tty_fd;
Michal Schmidt e1f787
         }
Michal Schmidt e1f787
 
Michal Schmidt e1f787
-        if ((r = reset_terminal_fd(tty_fd)) < 0)
Michal Schmidt e1f787
+        /* We don't want to force text mode.
Michal Schmidt e1f787
+         * plymouth may be showing pictures already from initrd. */
Michal Schmidt e1f787
+        r = reset_terminal_fd(tty_fd, false);
Michal Schmidt e1f787
+        if (r < 0)
Michal Schmidt e1f787
                 log_error("Failed to reset /dev/console: %s", strerror(-r));
Michal Schmidt e1f787
 
Michal Schmidt e1f787
         close_nointr_nofail(tty_fd);
Michal Schmidt e1f787
diff --git a/src/util.c b/src/util.c
Michal Schmidt e1f787
index 497fd05..ed939a2 100644
Michal Schmidt e1f787
--- a/src/util.c
Michal Schmidt e1f787
+++ b/src/util.c
Michal Schmidt e1f787
@@ -2472,7 +2472,7 @@ int ask(char *ret, const char *replies, const char *text, ...) {
Michal Schmidt e1f787
         }
Michal Schmidt e1f787
 }
Michal Schmidt e1f787
 
Michal Schmidt e1f787
-int reset_terminal_fd(int fd) {
Michal Schmidt e1f787
+int reset_terminal_fd(int fd, bool switch_to_text) {
Michal Schmidt e1f787
         struct termios termios;
Michal Schmidt e1f787
         int r = 0;
Michal Schmidt e1f787
 
Michal Schmidt e1f787
@@ -2488,7 +2488,8 @@ int reset_terminal_fd(int fd) {
Michal Schmidt e1f787
         ioctl(fd, TIOCNXCL);
Michal Schmidt e1f787
 
Michal Schmidt e1f787
         /* Switch to text mode */
Michal Schmidt e1f787
-        ioctl(fd, KDSETMODE, KD_TEXT);
Michal Schmidt e1f787
+        if (switch_to_text)
Michal Schmidt e1f787
+                ioctl(fd, KDSETMODE, KD_TEXT);
Michal Schmidt e1f787
 
Michal Schmidt e1f787
         /* Enable console unicode mode */
Michal Schmidt e1f787
         ioctl(fd, KDSKBMODE, K_UNICODE);
Michal Schmidt e1f787
@@ -2542,7 +2543,7 @@ int reset_terminal(const char *name) {
Michal Schmidt e1f787
         if (fd < 0)
Michal Schmidt e1f787
                 return fd;
Michal Schmidt e1f787
 
Michal Schmidt e1f787
-        r = reset_terminal_fd(fd);
Michal Schmidt e1f787
+        r = reset_terminal_fd(fd, true);
Michal Schmidt e1f787
         close_nointr_nofail(fd);
Michal Schmidt e1f787
 
Michal Schmidt e1f787
         return r;
Michal Schmidt e1f787
@@ -2736,7 +2737,8 @@ int acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocst
Michal Schmidt e1f787
         if (notify >= 0)
Michal Schmidt e1f787
                 close_nointr_nofail(notify);
Michal Schmidt e1f787
 
Michal Schmidt e1f787
-        if ((r = reset_terminal_fd(fd)) < 0)
Michal Schmidt e1f787
+        r = reset_terminal_fd(fd, true);
Michal Schmidt e1f787
+        if (r < 0)
Michal Schmidt e1f787
                 log_warning("Failed to reset terminal: %s", strerror(-r));
Michal Schmidt e1f787
 
Michal Schmidt e1f787
         return fd;
Michal Schmidt e1f787
diff --git a/src/util.h b/src/util.h
Michal Schmidt e1f787
index 944c7d2..441c75f 100644
Michal Schmidt e1f787
--- a/src/util.h
Michal Schmidt e1f787
+++ b/src/util.h
Michal Schmidt e1f787
@@ -325,7 +325,7 @@ int chvt(int vt);
Michal Schmidt e1f787
 int read_one_char(FILE *f, char *ret, bool *need_nl);
Michal Schmidt e1f787
 int ask(char *ret, const char *replies, const char *text, ...);
Michal Schmidt e1f787
 
Michal Schmidt e1f787
-int reset_terminal_fd(int fd);
Michal Schmidt e1f787
+int reset_terminal_fd(int fd, bool switch_to_text);
Michal Schmidt e1f787
 int reset_terminal(const char *name);
Michal Schmidt e1f787
 
Michal Schmidt e1f787
 int open_terminal(const char *name, int mode);