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

Hans de Goede hdegoede at redhat.com
Sat Mar 8 01:41:14 PST 2014


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/eventcomm.c | 10 ++++++++--
 src/synaptics.c | 30 +++++++++++++++++++++---------
 src/synproto.h  |  4 ++++
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/eventcomm.c b/src/eventcomm.c
index a0a2af0..49a8a3f 100644
--- a/src/eventcomm.c
+++ b/src/eventcomm.c
@@ -942,7 +942,11 @@ EventAutoDevProbe(InputInfoPtr pInfo, const char *device)
     if (device) {
         int fd = -1;
 
-        SYSCALL(fd = open(device, O_RDONLY));
+        if (pInfo->flags & XI86_SERVER_FD)
+            fd = pInfo->fd;
+        else
+            SYSCALL(fd = open(device, O_RDONLY));
+
         if (fd >= 0) {
             int rc;
             struct libevdev *evdev;
@@ -953,7 +957,9 @@ EventAutoDevProbe(InputInfoPtr pInfo, const char *device)
                 libevdev_free(evdev);
             }
 
-            SYSCALL(close(fd));
+            if (!(pInfo->flags & XI86_SERVER_FD))
+                SYSCALL(close(fd));
+
             /* if a device is set and not a touchpad (or already grabbed),
              * we must return FALSE.  Otherwise, we'll add a device that
              * wasn't requested for and repeat
diff --git a/src/synaptics.c b/src/synaptics.c
index f778d39..6df50e6 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -184,6 +184,10 @@ InputDriverRec SYNAPTICS = {
     SynapticsPreInit,
     SynapticsUnInit,
     NULL,
+    NULL,
+#ifdef XI86_DRV_CAP_SERVER_FD
+    XI86_DRV_CAP_SERVER_FD
+#endif
 };
 
 static XF86ModuleVersionInfo VersionRec = {
@@ -898,14 +902,16 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
             XisbFree(priv->comm.buffer);
             priv->comm.buffer = NULL;
         }
-        xf86CloseSerial(pInfo->fd);
+        if (!(pInfo->flags & XI86_SERVER_FD)) {
+            xf86CloseSerial(pInfo->fd);
+            pInfo->fd = -1;
+        }
     }
-    pInfo->fd = -1;
 
     return Success;
 
  SetupProc_fail:
-    if (pInfo->fd >= 0) {
+    if (pInfo->fd >= 0 && !(pInfo->flags & XI86_SERVER_FD)) {
         xf86CloseSerial(pInfo->fd);
         pInfo->fd = -1;
     }
@@ -996,8 +1002,10 @@ DeviceOn(DeviceIntPtr dev)
 
     priv->comm.buffer = XisbNew(pInfo->fd, INPUT_BUFFER_SIZE);
     if (!priv->comm.buffer) {
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
+        if (!(pInfo->flags & XI86_SERVER_FD)) {
+            xf86CloseSerial(pInfo->fd);
+            pInfo->fd = -1;
+        }
         return !Success;
     }
 
@@ -1007,8 +1015,10 @@ DeviceOn(DeviceIntPtr dev)
     if (!QueryHardware(pInfo)) {
         XisbFree(priv->comm.buffer);
         priv->comm.buffer = NULL;
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
+        if (!(pInfo->flags & XI86_SERVER_FD)) {
+            xf86CloseSerial(pInfo->fd);
+            pInfo->fd = -1;
+        }
         return !Success;
     }
 
@@ -1074,8 +1084,10 @@ DeviceOff(DeviceIntPtr dev)
             XisbFree(priv->comm.buffer);
             priv->comm.buffer = NULL;
         }
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
+        if (!(pInfo->flags & XI86_SERVER_FD)) {
+            xf86CloseSerial(pInfo->fd);
+            pInfo->fd = -1;
+        }
     }
     dev->public.on = FALSE;
     return rc;
diff --git a/src/synproto.h b/src/synproto.h
index f164393..d81ee42 100644
--- a/src/synproto.h
+++ b/src/synproto.h
@@ -36,6 +36,10 @@
 #include <xf86Xinput.h>
 #include <xisb.h>
 
+#ifndef XI86_SERVER_FD
+#define XI86_SERVER_FD 0x20
+#endif
+
 struct _SynapticsPrivateRec;
 typedef struct _SynapticsPrivateRec SynapticsPrivate;
 
-- 
1.8.4.2



More information about the xorg-devel mailing list