84b277
From a5236c816e1b8f7a56b2b4b0fa5ac2d5998e5b84 Mon Sep 17 00:00:00 2001
84b277
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
84b277
Date: Tue, 1 Jul 2014 22:20:11 -0400
84b277
Subject: [PATCH] vconsole-setup: run setfont before loadkeys
84b277
84b277
https://bugs.freedesktop.org/show_bug.cgi?id=80685
84b277
84b277
(cherry picked from commit abee28c56d523e55751b0c007d0bf812cc285c00)
84b277
84b277
Conflicts:
84b277
        src/vconsole/vconsole-setup.c
84b277
84b277
Related: #1002450
84b277
---
84b277
 src/vconsole/vconsole-setup.c | 49 ++++++++++++++++++++-----------------------
84b277
 1 file changed, 23 insertions(+), 26 deletions(-)
84b277
84b277
diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
84b277
index 7196ddf..25d15af 100644
84b277
--- a/src/vconsole/vconsole-setup.c
84b277
+++ b/src/vconsole/vconsole-setup.c
84b277
@@ -238,12 +238,10 @@ static void font_copy_to_all_vcs(int fd) {
84b277
 
84b277
 int main(int argc, char **argv) {
84b277
         const char *vc;
84b277
-        char *vc_keymap = NULL;
84b277
-        char *vc_keymap_toggle = NULL;
84b277
-        char *vc_font = NULL;
84b277
-        char *vc_font_map = NULL;
84b277
-        char *vc_font_unimap = NULL;
84b277
-        int fd = -1;
84b277
+        _cleanup_free_ char
84b277
+                *vc_keymap = NULL, *vc_keymap_toggle = NULL,
84b277
+                *vc_font = NULL, *vc_font_map = NULL, *vc_font_unimap = NULL;
84b277
+        _cleanup_close_ int fd = -1;
84b277
         bool utf8;
84b277
         pid_t font_pid = 0, keymap_pid = 0;
84b277
         bool font_copy = false;
84b277
@@ -265,12 +263,12 @@ int main(int argc, char **argv) {
84b277
         fd = open_terminal(vc, O_RDWR|O_CLOEXEC);
84b277
         if (fd < 0) {
84b277
                 log_error("Failed to open %s: %m", vc);
84b277
-                goto finish;
84b277
+                return EXIT_FAILURE;
84b277
         }
84b277
 
84b277
         if (!is_vconsole(fd)) {
84b277
                 log_error("Device %s is not a virtual console.", vc);
84b277
-                goto finish;
84b277
+                return EXIT_FAILURE;
84b277
         }
84b277
 
84b277
         utf8 = is_locale_utf8();
84b277
@@ -305,28 +303,27 @@ int main(int argc, char **argv) {
84b277
         else
84b277
                 disable_utf8(fd);
84b277
 
84b277
-        r = EXIT_FAILURE;
84b277
-        if (keymap_load(vc, vc_keymap, vc_keymap_toggle, utf8, &keymap_pid) >= 0 &&
84b277
-            font_load(vc, vc_font, vc_font_map, vc_font_unimap, &font_pid) >= 0)
84b277
-                r = EXIT_SUCCESS;
84b277
-
84b277
-finish:
84b277
-        if (keymap_pid > 0)
84b277
-                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
84b277
+        r = font_load(vc, vc_font, vc_font_map, vc_font_unimap, &font_pid);
84b277
+        if (r < 0) {
84b277
+                log_error("Failed to start " KBD_LOADKEYS ": %s", strerror(-r));
84b277
+                return EXIT_FAILURE;
84b277
+        }
84b277
 
84b277
-        if (font_pid > 0) {
84b277
+        if (font_pid > 0)
84b277
                 wait_for_terminate_and_warn(KBD_SETFONT, font_pid);
84b277
-                if (font_copy)
84b277
-                        font_copy_to_all_vcs(fd);
84b277
+
84b277
+        r = keymap_load(vc, vc_keymap, vc_keymap_toggle, utf8, &keymap_pid);
84b277
+        if (r < 0) {
84b277
+                log_error("Failed to start " KBD_SETFONT ": %s", strerror(-r));
84b277
+                return EXIT_FAILURE;
84b277
         }
84b277
 
84b277
-        free(vc_keymap);
84b277
-        free(vc_font);
84b277
-        free(vc_font_map);
84b277
-        free(vc_font_unimap);
84b277
+        if (keymap_pid > 0)
84b277
+                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
84b277
 
84b277
-        if (fd >= 0)
84b277
-                close_nointr_nofail(fd);
84b277
+        /* Only copy the font when we started setfont successfully */
84b277
+        if (font_copy && font_pid > 0)
84b277
+                font_copy_to_all_vcs(fd);
84b277
 
84b277
-        return r;
84b277
+        return EXIT_SUCCESS;
84b277
 }