[systemd-devel] [PATCH 1/6] udev: builtin-keyboard: move fetching the device node up

Peter Hutterer peter.hutterer at who-t.net
Sun Mar 22 18:30:37 PDT 2015


No point parsing the properties if we can't get the devnode to apply them
later. Plus, this makes future additions easier to slot in.
---
 src/udev/udev-builtin-keyboard.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c
index 8ab1be8..b7c8791 100644
--- a/src/udev/udev-builtin-keyboard.c
+++ b/src/udev/udev-builtin-keyboard.c
@@ -71,6 +71,14 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
         unsigned map_count = 0;
         unsigned release[1024];
         unsigned release_count = 0;
+        const char *node;
+
+        node = udev_device_get_devnode(dev);
+
+        if (!node) {
+                log_error("Error, no device node for '%s'", udev_device_get_syspath(dev));
+                return EXIT_FAILURE;
+        }
 
         udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev)) {
                 const char *key;
@@ -124,17 +132,10 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
         }
 
         if (map_count > 0 || release_count > 0) {
-                const char *node;
                 int fd;
                 unsigned i;
 
-                node = udev_device_get_devnode(dev);
-                if (!node) {
-                        log_error("Error, no device node for '%s'", udev_device_get_syspath(dev));
-                        return EXIT_FAILURE;
-                }
-
-                fd = open(udev_device_get_devnode(dev), O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
+                fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
                 if (fd < 0) {
                         log_error_errno(errno, "Error, opening device '%s': %m", node);
                         return EXIT_FAILURE;
-- 
2.3.2



More information about the systemd-devel mailing list