teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0298-localed-log-locale-keymap-changes-in-detail.patch

84b277
From d522b56345f2fe53a5ccac396c669d8f74088a6b Mon Sep 17 00:00:00 2001
84b277
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
84b277
Date: Wed, 3 Sep 2014 22:55:16 -0400
84b277
Subject: [PATCH] localed: log locale/keymap changes in detail
84b277
84b277
Converting X11 to legacy keymaps and back is a fucking mess. Let's
84b277
make it at least possible to request detailed logs of what is being
84b277
changed and why (LOG_DEBUG level).
84b277
84b277
At LOG_INFO level, we would log the requested change of X11 or console
84b277
keymap, but not the resulting change after conversion to console or X11.
84b277
Make sure that every change of configuration on disk has a matching
84b277
line in the logs.
84b277
84b277
Conflicts:
84b277
        src/locale/localed.c
84b277
84b277
(cherry picked from commit 502f961425f9dea1a85239766a3189695194da63)
84b277
84b277
Related: #1109145
84b277
---
84b277
 src/locale/localed.c | 84 ++++++++++++++++++++++++++++++++++++++--------------
84b277
 1 file changed, 61 insertions(+), 23 deletions(-)
84b277
84b277
diff --git a/src/locale/localed.c b/src/locale/localed.c
84b277
index a93b309..c22e12d 100644
84b277
--- a/src/locale/localed.c
84b277
+++ b/src/locale/localed.c
84b277
@@ -337,9 +337,11 @@ static int read_data(void) {
84b277
         return r < 0 ? r : q < 0 ? q : p;
84b277
 }
84b277
 
84b277
-static int write_data_locale(void) {
84b277
+static int write_data_locale(char ***settings) {
84b277
         int r, p;
84b277
-        char **l = NULL;
84b277
+        _cleanup_strv_free_ char **l = NULL;
84b277
+
84b277
+        /* Set values will be returned as strv in *settings on success. */
84b277
 
84b277
         r = load_env_file("/etc/locale.conf", NULL, &l);
84b277
         if (r < 0 && r != -ENOENT)
84b277
@@ -355,14 +357,12 @@ static int write_data_locale(void) {
84b277
                         continue;
84b277
                 }
84b277
 
84b277
-                if (asprintf(&t, "%s=%s", names[p], data[p]) < 0) {
84b277
-                        strv_free(l);
84b277
+                if (asprintf(&t, "%s=%s", names[p], data[p]) < 0)
84b277
                         return -ENOMEM;
84b277
-                }
84b277
+
84b277
 
84b277
                 u = strv_env_set(l, t);
84b277
                 free(t);
84b277
-                strv_free(l);
84b277
 
84b277
                 if (!u)
84b277
                         return -ENOMEM;
84b277
@@ -371,8 +371,6 @@ static int write_data_locale(void) {
84b277
         }
84b277
 
84b277
         if (strv_isempty(l)) {
84b277
-                strv_free(l);
84b277
-
84b277
                 if (unlink("/etc/locale.conf") < 0)
84b277
                         return errno == ENOENT ? 0 : -errno;
84b277
 
84b277
@@ -380,7 +378,11 @@ static int write_data_locale(void) {
84b277
         }
84b277
 
84b277
         r = write_env_file_label("/etc/locale.conf", l);
84b277
-        strv_free(l);
84b277
+        if (r < 0)
84b277
+                return r;
84b277
+
84b277
+        *settings = l;
84b277
+        l = NULL;
84b277
 
84b277
         return r;
84b277
 }
84b277
@@ -771,6 +773,12 @@ static int convert_vconsole_to_x11(DBusConnection *connection) {
84b277
                 if (r < 0)
84b277
                         log_error("Failed to set X11 keyboard layout: %s", strerror(-r));
84b277
 
84b277
+                log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'",
84b277
+                         strempty(state.x11_layout),
84b277
+                         strempty(state.x11_model),
84b277
+                         strempty(state.x11_variant),
84b277
+                         strempty(state.x11_options));
84b277
+
84b277
                 changed = bus_properties_changed_new(
84b277
                                 "/org/freedesktop/locale1",
84b277
                                 "org.freedesktop.locale1",
84b277
@@ -787,7 +795,8 @@ static int convert_vconsole_to_x11(DBusConnection *connection) {
84b277
 
84b277
                 if (!b)
84b277
                         return -ENOMEM;
84b277
-        }
84b277
+        } else
84b277
+                log_debug("X11 keyboard layout was not modified.");
84b277
 
84b277
         return 0;
84b277
 }
84b277
@@ -805,13 +814,18 @@ static int find_converted_keymap(char **new_keymap) {
84b277
 
84b277
         NULSTR_FOREACH(dir, KBD_KEYMAP_DIRS) {
84b277
                 _cleanup_free_ char *p = NULL, *pz = NULL;
84b277
+                bool uncompressed;
84b277
 
84b277
                 p = strjoin(dir, "xkb/", n, ".map", NULL);
84b277
                 pz = strjoin(dir, "xkb/", n, ".map.gz", NULL);
84b277
                 if (!p || !pz)
84b277
                         return -ENOMEM;
84b277
 
84b277
-                if (access(p, F_OK) == 0 || access(pz, F_OK) == 0) {
84b277
+                uncompressed = access(p, F_OK) == 0;
84b277
+                if (uncompressed || access(pz, F_OK) == 0) {
84b277
+                        log_debug("Found converted keymap %s at %s",
84b277
+                                  n, uncompressed ? p : pz);
84b277
+
84b277
                         *new_keymap = n;
84b277
                         n = NULL;
84b277
                         return 1;
84b277
@@ -885,13 +899,19 @@ static int find_legacy_keymap(char **new_keymap) {
84b277
                 }
84b277
 
84b277
                 /* The best matching entry so far, then let's save that */
84b277
-                if (matching > best_matching) {
84b277
-                        best_matching = matching;
84b277
+                if (matching >= MAX(best_matching, 1u)) {
84b277
+                        log_debug("Found legacy keymap %s with score %u",
84b277
+                                  a[0], matching);
84b277
 
84b277
-                        free(*new_keymap);
84b277
-                        *new_keymap = strdup(a[0]);
84b277
-                        if (!*new_keymap)
84b277
-                                return -ENOMEM;
84b277
+                        if (matching > best_matching) {
84b277
+                                best_matching = matching;
84b277
+
84b277
+                                free(*new_keymap);
84b277
+                                *new_keymap = strdup(a[0]);
84b277
+
84b277
+                                if (!*new_keymap)
84b277
+                                        return -ENOMEM;
84b277
+                        }
84b277
                 }
84b277
         }
84b277
 
84b277
@@ -943,6 +963,9 @@ static int convert_x11_to_vconsole(DBusConnection *connection) {
84b277
                 if (r < 0)
84b277
                         log_error("Failed to set virtual console keymap: %s", strerror(-r));
84b277
 
84b277
+                log_info("Changed virtual console keymap to '%s' toggle '%s'",
84b277
+                         strempty(state.vc_keymap), strempty(state.vc_keymap_toggle));
84b277
+
84b277
                 changed = bus_properties_changed_new(
84b277
                                 "/org/freedesktop/locale1",
84b277
                                 "org.freedesktop.locale1",
84b277
@@ -959,7 +982,8 @@ static int convert_x11_to_vconsole(DBusConnection *connection) {
84b277
                         return -ENOMEM;
84b277
 
84b277
                 return load_vconsole_keymap(connection, NULL);
84b277
-        }
84b277
+        } else
84b277
+                log_debug("Virtual console keymap was not modified.");
84b277
 
84b277
         return 0;
84b277
 }
84b277
@@ -968,6 +992,7 @@ static int append_locale(DBusMessageIter *i, const char *property, void *userdat
84b277
         int r, c = 0, p;
84b277
         char **l;
84b277
 
84b277
+        /* Check whether a variable changed and if it is valid */
84b277
         l = new0(char*, _PROP_MAX+1);
84b277
         if (!l)
84b277
                 return -ENOMEM;
84b277
@@ -1086,6 +1111,7 @@ static DBusHandlerResult locale_message_handler(
84b277
                 }
84b277
 
84b277
                 if (modified) {
84b277
+                        _cleanup_strv_free_ char **settings = NULL;
84b277
 
84b277
                         r = verify_polkit(connection, message, "org.freedesktop.locale1.set-locale", interactive, NULL, &error);
84b277
                         if (r < 0) {
84b277
@@ -1127,7 +1153,7 @@ static DBusHandlerResult locale_message_handler(
84b277
 
84b277
                         simplify();
84b277
 
84b277
-                        r = write_data_locale();
84b277
+                        r = write_data_locale(&settings);
84b277
                         if (r < 0) {
84b277
                                 log_error("Failed to set locale: %s", strerror(-r));
84b277
                                 return bus_send_error_reply(connection, message, NULL, r);
84b277
@@ -1135,7 +1161,13 @@ static DBusHandlerResult locale_message_handler(
84b277
 
84b277
                         push_data(connection);
84b277
 
84b277
-                        log_info("Changed locale information.");
84b277
+                        if (settings) {
84b277
+                                _cleanup_free_ char *line;
84b277
+
84b277
+                                line = strv_join(settings, ", ");
84b277
+                                log_info("Changed locale to %s.", strnull(line));
84b277
+                        } else
84b277
+                                log_info("Changed locale to unset.");
84b277
 
84b277
                         changed = bus_properties_changed_new(
84b277
                                         "/org/freedesktop/locale1",
84b277
@@ -1143,8 +1175,10 @@ static DBusHandlerResult locale_message_handler(
84b277
                                         "Locale\0");
84b277
                         if (!changed)
84b277
                                 goto oom;
84b277
-                } else
84b277
+                } else {
84b277
+                        log_debug("Locale settings were not modified.");
84b277
                         strv_free(l);
84b277
+                }
84b277
 
84b277
         } else if (dbus_message_is_method_call(message, "org.freedesktop.locale1", "SetVConsoleKeyboard")) {
84b277
 
84b277
@@ -1188,7 +1222,8 @@ static DBusHandlerResult locale_message_handler(
84b277
                                 return bus_send_error_reply(connection, message, NULL, r);
84b277
                         }
84b277
 
84b277
-                        log_info("Changed virtual console keymap to '%s'", strempty(state.vc_keymap));
84b277
+                        log_info("Changed virtual console keymap to '%s' toggle '%s'",
84b277
+                                 strempty(state.vc_keymap), strempty(state.vc_keymap_toggle));
84b277
 
84b277
                         r = load_vconsole_keymap(connection, NULL);
84b277
                         if (r < 0)
84b277
@@ -1266,7 +1301,10 @@ static DBusHandlerResult locale_message_handler(
84b277
                                 return bus_send_error_reply(connection, message, NULL, r);
84b277
                         }
84b277
 
84b277
-                        log_info("Changed X11 keyboard layout to '%s'", strempty(state.x11_layout));
84b277
+                        log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'", strempty(state.x11_layout),
84b277
+                                 strempty(state.x11_model),
84b277
+                                 strempty(state.x11_variant),
84b277
+                                 strempty(state.x11_options));
84b277
 
84b277
                         changed = bus_properties_changed_new(
84b277
                                         "/org/freedesktop/locale1",