dcavalca / rpms / systemd

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