anitazha / rpms / systemd

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