ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
dd65c9
From 3b4e03492fd157ab87ea625a8ad1eb91cef7396b Mon Sep 17 00:00:00 2001
dd65c9
From: Peter Hutterer <peter.hutterer@who-t.net>
dd65c9
Date: Fri, 20 Mar 2015 13:17:20 +1000
dd65c9
Subject: [PATCH] udev: builtin-keyboard: move actual key mapping to a helper
dd65c9
 function
dd65c9
dd65c9
No changes in the mapping, but previously we opened the device only on
dd65c9
successful parsing. Now we open the mapping as soon as we have a value that
dd65c9
looks interesting. Since errors are supposed to be the exception, not the
dd65c9
rule, this is probably fine.
dd65c9
dd65c9
(cherry picked from commit c9a8e34094733018727677fee44be2c2952224c0)
dd65c9
dd65c9
Resolves: #1500119
dd65c9
---
23b3cf
 src/udev/udev-builtin-keyboard.c | 58 ++++++++++++++++++--------------
dd65c9
 1 file changed, 33 insertions(+), 25 deletions(-)
dd65c9
dd65c9
diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c
c62b8e
index 515edd45ce..f33401790c 100644
dd65c9
--- a/src/udev/udev-builtin-keyboard.c
dd65c9
+++ b/src/udev/udev-builtin-keyboard.c
dd65c9
@@ -66,12 +66,41 @@ static int install_force_release(struct udev_device *dev, const unsigned *releas
dd65c9
         return ret;
dd65c9
 }
dd65c9
 
dd65c9
-static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], bool test) {
dd65c9
-        struct udev_list_entry *entry;
dd65c9
+static void map_keycode(int fd, const char *devnode, int scancode, const char *keycode)
dd65c9
+{
dd65c9
         struct {
dd65c9
                 unsigned scan;
dd65c9
                 unsigned key;
dd65c9
         } map;
dd65c9
+        char *endptr;
dd65c9
+        const struct key *k;
dd65c9
+        unsigned keycode_num;
dd65c9
+
dd65c9
+        /* translate identifier to key code */
dd65c9
+        k = keyboard_lookup_key(keycode, strlen(keycode));
dd65c9
+        if (k) {
dd65c9
+                keycode_num = k->id;
dd65c9
+        } else {
dd65c9
+                /* check if it's a numeric code already */
dd65c9
+                keycode_num = strtoul(keycode, &endptr, 0);
dd65c9
+                if (endptr[0] !='\0') {
dd65c9
+                        log_error("Error, unknown key identifier '%s'", keycode);
dd65c9
+                        return;
dd65c9
+                }
dd65c9
+        }
dd65c9
+
dd65c9
+        map.scan = scancode;
dd65c9
+        map.key = keycode_num;
dd65c9
+
dd65c9
+        log_debug("keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
dd65c9
+                  map.scan, map.scan, map.key, map.key);
dd65c9
+
dd65c9
+        if (ioctl(fd, EVIOCSKEYCODE, &map) < 0)
dd65c9
+                log_error_errno(errno, "Error calling EVIOCSKEYCODE on device node '%s' (scan code 0x%x, key code %d): %m", devnode, map.scan, map.key);
dd65c9
+}
dd65c9
+
dd65c9
+static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], bool test) {
dd65c9
+        struct udev_list_entry *entry;
dd65c9
         unsigned release[1024];
dd65c9
         unsigned release_count = 0;
dd65c9
         _cleanup_close_ int fd = -1;
dd65c9
@@ -85,10 +114,9 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
dd65c9
 
dd65c9
         udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev)) {
dd65c9
                 const char *key;
dd65c9
-                unsigned scancode, keycode_num;
dd65c9
                 char *endptr;
dd65c9
+                unsigned scancode;
dd65c9
                 const char *keycode;
dd65c9
-                const struct key *k;
dd65c9
 
dd65c9
                 key = udev_list_entry_get_name(entry);
dd65c9
                 if (!startswith(key, "KEYBOARD_KEY_"))
dd65c9
@@ -115,19 +143,6 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
dd65c9
                                 continue;
dd65c9
                 }
dd65c9
 
dd65c9
-                /* translate identifier to key code */
dd65c9
-                k = keyboard_lookup_key(keycode, strlen(keycode));
dd65c9
-                if (k) {
dd65c9
-                        keycode_num = k->id;
dd65c9
-                } else {
dd65c9
-                        /* check if it's a numeric code already */
dd65c9
-                        keycode_num = strtoul(keycode, &endptr, 0);
dd65c9
-                        if (endptr[0] !='\0') {
dd65c9
-                                log_error("Error, unknown key identifier '%s'", keycode);
dd65c9
-                                continue;
dd65c9
-                        }
dd65c9
-                }
dd65c9
-
dd65c9
                 if (fd == -1) {
dd65c9
                         fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
dd65c9
                         if (fd < 0) {
dd65c9
@@ -136,14 +151,7 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
dd65c9
                         }
dd65c9
                 }
dd65c9
 
dd65c9
-                map.scan = scancode;
dd65c9
-                map.key = keycode_num;
dd65c9
-
dd65c9
-                log_debug("keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
dd65c9
-                          map.scan, map.scan, map.key, map.key);
dd65c9
-
dd65c9
-                if (ioctl(fd, EVIOCSKEYCODE, &map) < 0)
dd65c9
-                        log_error_errno(errno, "Error calling EVIOCSKEYCODE on device node '%s' (scan code 0x%x, key code %d): %m", node, map.scan, map.key);
dd65c9
+                map_keycode(fd, node, scancode, keycode);
dd65c9
         }
dd65c9
 
dd65c9
         /* install list of force-release codes */