From a136c2cdd84c93c2fa5e1cedb20f5acac80df5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 Oct 2020 18:01:20 +0200 Subject: [PATCH 1/3] hwdb: drop quotes from XKB_FIXED_*= properties The properties are not unquoted by udev, so the quotes effectively became part of the value. Even though those properties were added quite a while ago (086c001e29a86287d7b639cb71d1fc6408920c53, d7d31692bf7cde5dce7f4ed3cae429a5b302a9f0), they never started being used (because of issues with having multiple layouts), see https://gitlab.gnome.org/GNOME/mutter/-/issues/906, https://bugzilla.gnome.org/show_bug.cgi?id=775681. Let's remove the quotes while we still can. From https://bugzilla.gnome.org/show_bug.cgi?id=775681#c7: > Note to self: the values for XKB_FIXED_LAYOUT and XKB_FIXED_VARIANT are > quoted, meaning that we need to remove the quotes before passing the values > from udev_device_get_property_value() to xkb_keymap_new_from_names() > otherwise the compilation of the keymap fails (please don't ask how I found > out...) --- hwdb.d/60-keyboard.hwdb | 12 ++++++------ hwdb.d/parse_hwdb.py | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hwdb.d/60-keyboard.hwdb b/hwdb.d/60-keyboard.hwdb index 66672c5b53..97800f4364 100644 --- a/hwdb.d/60-keyboard.hwdb +++ b/hwdb.d/60-keyboard.hwdb @@ -72,14 +72,14 @@ # A device with a fixed keyboard layout that must not be changed by # the desktop environment may specify that layout as: -# XKB_FIXED_LAYOUT="us" -# XKB_FIXED_VARIANT="" +# XKB_FIXED_LAYOUT=us +# XKB_FIXED_VARIANT= # Examples of such devices: the Yubikey or other key-code generating # devices. # A device where the scan code to key code mapping is insufficient and # requires a special key code to symbol configuration may specify that with: -# XKB_FIXED_MODEL="xkbmodel" +# XKB_FIXED_MODEL=xkbmodel # Examples of such devices: Chromebooks where the top row is used for both # media and F1-F10 keys. @@ -1796,8 +1796,8 @@ evdev:input:b0003v1050p0111:* evdev:input:b0003v1050p0116:* # OKE Electron Company USB barcode reader evdev:input:b0003v05FEp1010:* - XKB_FIXED_LAYOUT="us" - XKB_FIXED_VARIANT="" + XKB_FIXED_LAYOUT=us + XKB_FIXED_VARIANT= ######################### LACK OF MODIFIER LEDS ############################ # This section lists keyboard which do not have their own LEDs for some @@ -1846,4 +1846,4 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnLENOVO:pn*:pvrThinkPadX1Carbon3rd:* # Chromebooks evdev:atkbd:dmi:bvn*:bvr*:bd*:svnHewlett-Packard*:pnFalco:* evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pnPeppy:* - XKB_FIXED_MODEL="chromebook" + XKB_FIXED_MODEL=chromebook diff --git a/hwdb.d/parse_hwdb.py b/hwdb.d/parse_hwdb.py index 09751634a4..4174c7598f 100755 --- a/hwdb.d/parse_hwdb.py +++ b/hwdb.d/parse_hwdb.py @@ -32,7 +32,7 @@ try: from pyparsing import (Word, White, Literal, ParserElement, Regex, LineEnd, OneOrMore, Combine, Or, Optional, Suppress, Group, nums, alphanums, printables, - stringEnd, pythonStyleComment, QuotedString, + stringEnd, pythonStyleComment, ParseBaseException) except ImportError: print('pyparsing is not available') @@ -54,7 +54,6 @@ EOL = LineEnd().suppress() EMPTYLINE = LineEnd() COMMENTLINE = pythonStyleComment + EOL INTEGER = Word(nums) -STRING = QuotedString('"') REAL = Combine((INTEGER + Optional('.' + Optional(INTEGER))) ^ ('.' + INTEGER)) SIGNED_REAL = Combine(Optional(Word('-+')) + REAL) UDEV_TAG = Word(string.ascii_uppercase, alphanums + '_') @@ -94,7 +93,8 @@ def hwdb_grammar(): matchline = (matchline_typed | matchline_general) + EOL propertyline = (White(' ', exact=1).suppress() + - Combine(UDEV_TAG - '=' - Word(alphanums + '_=:@*.!-;, "') - Optional(pythonStyleComment)) + + Combine(UDEV_TAG - '=' - Optional(Word(alphanums + '_=:@*.!-;, "')) + - Optional(pythonStyleComment)) + EOL) propertycomment = White(' ', exact=1) + pythonStyleComment + EOL @@ -114,6 +114,7 @@ def property_grammar(): dpi_setting = (Optional('*')('DEFAULT') + INTEGER('DPI') + Suppress('@') + INTEGER('HZ'))('SETTINGS*') mount_matrix_row = SIGNED_REAL + ',' + SIGNED_REAL + ',' + SIGNED_REAL mount_matrix = (mount_matrix_row + ';' + mount_matrix_row + ';' + mount_matrix_row)('MOUNT_MATRIX') + xkb_setting = Optional(Word(alphanums + '+-/@._')) props = (('MOUSE_DPI', Group(OneOrMore(dpi_setting))), ('MOUSE_WHEEL_CLICK_ANGLE', INTEGER), @@ -138,9 +139,9 @@ def property_grammar(): ('POINTINGSTICK_CONST_ACCEL', REAL), ('ID_INPUT_JOYSTICK_INTEGRATION', Or(('internal', 'external'))), ('ID_INPUT_TOUCHPAD_INTEGRATION', Or(('internal', 'external'))), - ('XKB_FIXED_LAYOUT', STRING), - ('XKB_FIXED_VARIANT', STRING), - ('XKB_FIXED_MODEL', STRING), + ('XKB_FIXED_LAYOUT', xkb_setting), + ('XKB_FIXED_VARIANT', xkb_setting), + ('XKB_FIXED_MODEL', xkb_setting), ('KEYBOARD_LED_NUMLOCK', Literal('0')), ('KEYBOARD_LED_CAPSLOCK', Literal('0')), ('ACCEL_MOUNT_MATRIX', mount_matrix), From afe87974dd57741f74dd87165b251886f24c859f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Oct 2020 17:12:42 +0200 Subject: [PATCH 2/3] sd-hwdb: allow empty properties So far we didn't allow empty properties, but it makes sense to do so, for example to distinguish empty data from lack of data. It also makes it easy to override properties (back to the empty) value for specific cases. --- src/libsystemd/sd-hwdb/hwdb-util.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index 1b642b6851..c2bfcd1d42 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -456,10 +456,9 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c while (isblank(line[0]) && isblank(line[1])) line++; - if (isempty(line + 1) || isempty(value)) + if (isempty(line + 1)) return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL), - "Empty %s in \"%s=%s\", ignoring", - isempty(line + 1) ? "key" : "value", + "Empty key in \"%s=%s\", ignoring", line, value); STRV_FOREACH(entry, match_list) From 327d8f3ab8dc14189ecb0ca29d3107699fec4d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Oct 2020 17:23:40 +0200 Subject: [PATCH 3/3] sd-hwdb: reduce variable scope, use periods --- src/libsystemd/sd-hwdb/hwdb-util.c | 35 ++++++++++++------------------ 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index c2bfcd1d42..2266b67adb 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -105,12 +105,10 @@ static struct trie_node *node_lookup(const struct trie_node *node, uint8_t c) { } static void trie_node_cleanup(struct trie_node *node) { - size_t i; - if (!node) return; - for (i = 0; i < node->children_count; i++) + for (size_t i = 0; i < node->children_count; i++) trie_node_cleanup(node->children[i].child); free(node->children); free(node->values); @@ -191,10 +189,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, static int trie_insert(struct trie *trie, struct trie_node *node, const char *search, const char *key, const char *value, const char *filename, uint16_t file_priority, uint32_t line_number, bool compat) { - size_t i = 0; int r = 0; - for (;;) { + for (size_t i = 0;; i++) { size_t p; uint8_t c; struct trie_node *child; @@ -273,7 +270,6 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se } node = child; - i++; } } @@ -289,20 +285,17 @@ struct trie_f { /* calculate the storage space for the nodes, children arrays, value arrays */ static void trie_store_nodes_size(struct trie_f *trie, struct trie_node *node, bool compat) { - uint64_t i; - - for (i = 0; i < node->children_count; i++) + for (uint64_t i = 0; i < node->children_count; i++) trie_store_nodes_size(trie, node->children[i].child, compat); trie->strings_off += sizeof(struct trie_node_f); - for (i = 0; i < node->children_count; i++) + for (uint64_t i = 0; i < node->children_count; i++) trie->strings_off += sizeof(struct trie_child_entry_f); - for (i = 0; i < node->values_count; i++) + for (uint64_t i = 0; i < node->values_count; i++) trie->strings_off += compat ? sizeof(struct trie_value_entry_f) : sizeof(struct trie_value_entry2_f); } static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, bool compat) { - uint64_t i; struct trie_node_f n = { .prefix_off = htole64(trie->strings_off + node->prefix_off), .children_count = node->children_count, @@ -318,7 +311,7 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, boo } /* post-order recursion */ - for (i = 0; i < node->children_count; i++) { + for (uint64_t i = 0; i < node->children_count; i++) { int64_t child_off; child_off = trie_store_nodes(trie, node->children[i].child, compat); @@ -343,7 +336,7 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, boo } /* append values array */ - for (i = 0; i < node->values_count; i++) { + for (uint64_t i = 0; i < node->values_count; i++) { struct trie_value_entry2_f v = { .key_off = htole64(trie->strings_off + node->values[i].key_off), .value_off = htole64(trie->strings_off + node->values[i].value_off), @@ -447,7 +440,7 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c value = strchr(line, '='); if (!value) return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL), - "Key-value pair expected but got \"%s\", ignoring", line); + "Key-value pair expected but got \"%s\", ignoring.", line); value[0] = '\0'; value++; @@ -458,7 +451,7 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c if (isempty(line + 1)) return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL), - "Empty key in \"%s=%s\", ignoring", + "Empty key in \"%s=%s\", ignoring.", line, value); STRV_FOREACH(entry, match_list) @@ -493,7 +486,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr if (r == 0) break; - ++line_number; + line_number ++; /* comment line */ if (line[0] == '#') @@ -517,7 +510,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr if (line[0] == ' ') { r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL), - "Match expected but got indented property \"%s\", ignoring line", line); + "Match expected but got indented property \"%s\", ignoring line.", line); break; } @@ -533,7 +526,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr case HW_MATCH: if (len == 0) { r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL), - "Property expected, ignoring record with no properties"); + "Property expected, ignoring record with no properties."); state = HW_NONE; match_list = strv_free(match_list); break; @@ -565,7 +558,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr if (line[0] != ' ') { r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL), - "Property or empty line expected, got \"%s\", ignoring record", line); + "Property or empty line expected, got \"%s\", ignoring record.", line); state = HW_NONE; match_list = strv_free(match_list); break; @@ -580,7 +573,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr if (state == HW_MATCH) log_syntax(NULL, LOG_WARNING, filename, line_number, 0, - "Property expected, ignoring record with no properties"); + "Property expected, ignoring record with no properties."); return r; }