]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
localed: also report when we couldn't convert X11→console
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 May 2016 02:43:12 +0000 (22:43 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 6 Jun 2016 13:22:33 +0000 (09:22 -0400)
Rework the code a bit where find_converted_keymap cannot (and should not) be
called with a null layout, so streq can be used instead of streq_ptr, etc.

Note that the behaviour of vconsole_convert_to_x11 and x11_convert_to_vconsole
is not symmetrical. When the latter cannot find a match, it simply makes the
vconsole mapping empty. But vconsole_convert_to_x11 leaves the x11 layout
unchanged. I don't know what the proper solution is here, so I'm just adding
more verbose logging without changing the logic.

src/locale/keymap-util.c
src/locale/test-keymap-util.c

index b6cbf12c7e2dc47f859ddfb31f8e9a6443f7d919..fe29594ccc9ca29296ed03a36237b0e2a1b7e0ca 100644 (file)
 #include "strv.h"
 
 static bool startswith_comma(const char *s, const char *prefix) {
-        const char *t;
+        s = startswith(s, prefix);
+        if (!s)
+                return false;
 
-        return s && (t = startswith(s, prefix)) && (*t == ',');
+        return *s == ',';
 }
 
 static const char* strnulldash(const char *s) {
@@ -529,6 +531,8 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
         unsigned best_matching = 0;
         int r;
 
+        assert(!isempty(c->x11_layout));
+
         f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
         if (!f)
                 return -errno;
@@ -544,7 +548,7 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
                         break;
 
                 /* Determine how well matching this entry is */
-                if (streq_ptr(c->x11_layout, a[1]))
+                if (streq(c->x11_layout, a[1]))
                         /* If we got an exact match, this is best */
                         matching = 10;
                 else {
@@ -611,7 +615,7 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
                 }
         }
 
-        return 0;
+        return (bool) *new_keymap;
 }
 
 int find_language_fallback(const char *lang, char **language) {
@@ -648,7 +652,6 @@ int x11_convert_to_vconsole(Context *c) {
         bool modified = false;
 
         if (isempty(c->x11_layout)) {
-
                 modified =
                         !isempty(c->vc_keymap) ||
                         !isempty(c->vc_keymap_toggle);
@@ -666,6 +669,12 @@ int x11_convert_to_vconsole(Context *c) {
                         if (r < 0)
                                 return r;
                 }
+                if (r == 0)
+                        /* We search for layout-variant match first, but then we also look
+                         * for anything which matches just the layout. So it's accurate to say
+                         * that we couldn't find anything which matches the layout. */
+                        log_notice("No conversion to virtual console map found for \"%s\".",
+                                   c->x11_layout);
 
                 if (!streq_ptr(c->vc_keymap, new_keymap)) {
                         free(c->vc_keymap);
index 680aae622845f584f7bad36005de166c152053e5..8dde764a50eb28c8e5cbaa43725c25b854cdecd7 100644 (file)
@@ -84,11 +84,11 @@ static void test_find_legacy_keymap(void) {
         assert_se(ans == NULL);
 
         c.x11_layout = (char*) "pl";
-        assert_se(find_legacy_keymap(&c, &ans) == 0); /* should this be 1? */
+        assert_se(find_legacy_keymap(&c, &ans) == 1);
         assert_se(streq(ans, "pl2"));
 
         c.x11_layout = (char*) "pl,ru";
-        assert_se(find_legacy_keymap(&c, &ans2) == 0); /* should this be 1? */
+        assert_se(find_legacy_keymap(&c, &ans2) == 1);
         assert_se(streq(ans, "pl2"));
 }