[PATCH xf86-input-evdev] evdev: Add support for server managed fds

Hans de Goede hdegoede at redhat.com
Wed Jan 15 06:34:30 PST 2014


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev.c | 44 ++++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index d1ed9ee..e1960af 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -97,6 +97,10 @@
 #define ABS_MT_TRACKING_ID 0x39
 #endif
 
+#ifndef XI86_SERVER_FD
+#define XI86_SERVER_FD 0x20
+#endif
+
 static const char *evdevDefaults[] = {
     "XkbRules",     "evdev",
     "XkbModel",     "pc104", /* the right model for 'us' */
@@ -2478,32 +2482,32 @@ EvdevOpenDevice(InputInfoPtr pInfo)
         xf86IDrvMsg(pInfo, X_CONFIG, "Device: \"%s\"\n", device);
     }
 
-    if (pInfo->fd < 0)
+    if (!(pInfo->flags & XI86_SERVER_FD) && pInfo->fd < 0)
     {
         do {
             pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0);
         } while (pInfo->fd < 0 && errno == EINTR);
+    }
 
-        if (pInfo->fd < 0) {
-            xf86IDrvMsg(pInfo, X_ERROR, "Unable to open evdev device \"%s\".\n", device);
-            return BadValue;
-        }
+    if (pInfo->fd < 0) {
+        xf86IDrvMsg(pInfo, X_ERROR, "Unable to open evdev device \"%s\".\n", device);
+        return BadValue;
+    }
 
-        if (libevdev_get_fd(pEvdev->dev) != -1) {
-            struct input_event ev;
+    if (libevdev_get_fd(pEvdev->dev) != -1) {
+        struct input_event ev;
 
-            libevdev_change_fd(pEvdev->dev, pInfo->fd);
-            /* re-sync libevdev's view of the device, but
-               we don't care about the actual events here */
-            libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
-            while (libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_SYNC, &ev) == LIBEVDEV_READ_STATUS_SYNC)
-                ;
-        } else {
-            int rc = libevdev_set_fd(pEvdev->dev, pInfo->fd);
-            if (rc < 0) {
-                xf86IDrvMsg(pInfo, X_ERROR, "Unable to query fd: %s\n", strerror(-rc));
-                return BadValue;
-            }
+        libevdev_change_fd(pEvdev->dev, pInfo->fd);
+        /* re-sync libevdev's view of the device, but
+           we don't care about the actual events here */
+        libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
+        while (libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_SYNC, &ev) == LIBEVDEV_READ_STATUS_SYNC)
+            ;
+    } else {
+        int rc = libevdev_set_fd(pEvdev->dev, pInfo->fd);
+        if (rc < 0) {
+            xf86IDrvMsg(pInfo, X_ERROR, "Unable to query fd: %s\n", strerror(-rc));
+            return BadValue;
         }
     }
 
@@ -2531,7 +2535,7 @@ static void
 EvdevCloseDevice(InputInfoPtr pInfo)
 {
     EvdevPtr pEvdev = pInfo->private;
-    if (pInfo->fd >= 0)
+    if (!(pInfo->flags & XI86_SERVER_FD) && pInfo->fd >= 0)
     {
         close(pInfo->fd);
         pInfo->fd = -1;
-- 
1.8.4.2



More information about the xorg-devel mailing list