anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0554-udev-builtin-keyboard-immediately-EVIOCSKEYCODE-when.patch

dd65c9
From 4f9b03c28555799f8672b905323bf6d1f95eb13f Mon Sep 17 00:00:00 2001
dd65c9
From: Peter Hutterer <peter.hutterer@who-t.net>
dd65c9
Date: Fri, 20 Mar 2015 12:52:46 +1000
dd65c9
Subject: [PATCH] udev: builtin-keyboard: immediately EVIOCSKEYCODE when we
dd65c9
 have a pair
dd65c9
dd65c9
Rather than building a map and looping through the map, immediately call the
dd65c9
ioctl when we have a successfully parsed property.
dd65c9
dd65c9
This has a side-effect: before the maximum number of ioctls was limited to the
dd65c9
size of the map (1024), now it is unlimited.
dd65c9
dd65c9
(cherry picked from commit cfba2656e3b4a9c5e03db4ec0a8f76c3762d35a8)
dd65c9
dd65c9
Resolves: #1500119
dd65c9
---
23b3cf
 src/udev/udev-builtin-keyboard.c | 45 +++++++++++++-------------------
dd65c9
 1 file changed, 18 insertions(+), 27 deletions(-)
dd65c9
dd65c9
diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c
c62b8e
index bde7bf07fb..515edd45ce 100644
dd65c9
--- a/src/udev/udev-builtin-keyboard.c
dd65c9
+++ b/src/udev/udev-builtin-keyboard.c
dd65c9
@@ -71,10 +71,10 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
dd65c9
         struct {
dd65c9
                 unsigned scan;
dd65c9
                 unsigned key;
dd65c9
-        } map[1024];
dd65c9
-        unsigned map_count = 0;
dd65c9
+        } map;
dd65c9
         unsigned release[1024];
dd65c9
         unsigned release_count = 0;
dd65c9
+        _cleanup_close_ int fd = -1;
dd65c9
         const char *node;
dd65c9
 
dd65c9
         node = udev_device_get_devnode(dev);
dd65c9
@@ -128,37 +128,28 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
dd65c9
                         }
dd65c9
                 }
dd65c9
 
dd65c9
-                map[map_count].scan = scancode;
dd65c9
-                map[map_count].key = keycode_num;
dd65c9
-                if (map_count < ELEMENTSOF(map)-1)
dd65c9
-                        map_count++;
dd65c9
-        }
dd65c9
-
dd65c9
-        if (map_count > 0 || release_count > 0) {
dd65c9
-                int fd;
dd65c9
-                unsigned i;
dd65c9
-
dd65c9
-                fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
dd65c9
-                if (fd < 0) {
dd65c9
-                        log_error_errno(errno, "Error, opening device '%s': %m", node);
dd65c9
-                        return EXIT_FAILURE;
dd65c9
+                if (fd == -1) {
dd65c9
+                        fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
dd65c9
+                        if (fd < 0) {
dd65c9
+                                log_error_errno(errno, "Error, opening device '%s': %m", node);
dd65c9
+                                return EXIT_FAILURE;
dd65c9
+                        }
dd65c9
                 }
dd65c9
 
dd65c9
-                /* install list of map codes */
dd65c9
-                for (i = 0; i < map_count; i++) {
dd65c9
-                        log_debug("keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
dd65c9
-                                  map[i].scan, map[i].scan, map[i].key, map[i].key);
dd65c9
-                        if (ioctl(fd, EVIOCSKEYCODE, &map[i]) < 0)
dd65c9
-                                log_error_errno(errno, "Error calling EVIOCSKEYCODE on device node '%s' (scan code 0x%x, key code %d): %m", node, map[i].scan, map[i].key);
dd65c9
-                }
dd65c9
+                map.scan = scancode;
dd65c9
+                map.key = keycode_num;
dd65c9
 
dd65c9
-                /* install list of force-release codes */
dd65c9
-                if (release_count > 0)
dd65c9
-                        install_force_release(dev, release, release_count);
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
-                close(fd);
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
         }
dd65c9
 
dd65c9
+        /* install list of force-release codes */
dd65c9
+        if (release_count > 0)
dd65c9
+                install_force_release(dev, release, release_count);
dd65c9
+
dd65c9
         return EXIT_SUCCESS;
dd65c9
 }
dd65c9