[systemd-devel] [PATCH] vconsole: properly set terminal UTF-8 mode

Andrey Borzenkov arvidjaar at gmail.com
Fri Nov 5 07:35:15 PDT 2010


We cannot assume terminal is in UTF-8 (actually, unless
setup by initrd it likely is not). Properly set requested
mode. This avoids errors similar to

sh-4.1# /lib/systemd/systemd-vconsole-setup
Failed to open syslog for logging: No such file or directory
loadkeys: warning: loading Unicode keymap on non-Unicode console
    (perhaps you want to do `kbd_mode -u'?)

and broken fonts.

Signed-off-by: Andrey Borzenkov <arvidjaar at gmail.com>

---
 src/vconsole-setup.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/vconsole-setup.c b/src/vconsole-setup.c
index 7703361..af7f37d 100644
--- a/src/vconsole-setup.c
+++ b/src/vconsole-setup.c
@@ -60,20 +60,28 @@ static bool is_locale_utf8(void) {
         return streq(set, "UTF-8");
 }
 
-static int disable_utf8(int fd) {
+static int set_utf8(int fd, bool utf8) {
         int r = 0, k;
 
-        if (ioctl(fd, KDSKBMODE, K_XLATE) < 0)
-                r = -errno;
+	if (utf8) {
+		if (ioctl(fd, KDSKBMODE, K_UNICODE) < 0)
+			r = -errno;
 
-        if (loop_write(fd, "\033%@", 3, false) < 0)
-                r = -errno;
+		if (loop_write(fd, "\033%G", 3, false) < 0)
+			r = -errno;
+	} else {
+		if (ioctl(fd, KDSKBMODE, K_XLATE) < 0)
+			r = -errno;
 
-        if ((k = write_one_line_file("/sys/module/vt/parameters/default_utf8", "0")) < 0)
+		if (loop_write(fd, "\033%@", 3, false) < 0)
+			r = -errno;
+	}
+
+        if ((k = write_one_line_file("/sys/module/vt/parameters/default_utf8", utf8 ? "1" : "0")) < 0)
                 r = k;
 
         if (r < 0)
-                log_warning("Failed to disable UTF-8: %s", strerror(errno));
+                log_warning("Failed to %s UTF-8: %s", utf8 ? "enable" : "disable", strerror(errno));
 
         return r;
 }
@@ -322,8 +330,7 @@ int main(int argc, char **argv) {
                 goto finish;
         }
 
-        if (!utf8)
-                disable_utf8(fd);
+	set_utf8(fd, utf8);
 
         if (load_keymap(vc, vc_keymap, utf8, &keymap_pid) >= 0 &&
             load_font(vc, vc_font, vc_font_map, vc_font_unimap, &font_pid) >= 0)
-- 
tg: (4149f86..) upstream/kbd-utf8 (depends on: master)


More information about the systemd-devel mailing list