[PATCH v2 synaptics] synaptics: Add support for server managed fds

Hans de Goede hdegoede at redhat.com
Sun Mar 9 21:17:23 PDT 2014


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Give this one a test please, seems to work on first glance.
Changes to v1:
- use helper function for closing the fd, avoids forgetting the flag check
- Optimise DeviceOn to have a single error handling path
- DeviceOn:DeviceOnHook() error handling missed out on the updated call,
  fixed now

Cheers,
   Peter

 src/eventcomm.c | 10 ++++++++--
 src/synaptics.c | 62 ++++++++++++++++++++++++++++++---------------------------
 src/synproto.h  |  4 ++++
 3 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/src/eventcomm.c b/src/eventcomm.c
index 7c4aa85..bff332f 100644
--- a/src/eventcomm.c
+++ b/src/eventcomm.c
@@ -933,7 +933,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;
@@ -944,7 +948,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 c819982..3ae67f9 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -168,6 +168,10 @@ InputDriverRec SYNAPTICS = {
     SynapticsPreInit,
     SynapticsUnInit,
     NULL,
+    NULL,
+#ifdef XI86_DRV_CAP_SERVER_FD
+    XI86_DRV_CAP_SERVER_FD
+#endif
 };
 
 static XF86ModuleVersionInfo VersionRec = {
@@ -199,6 +203,15 @@ _X_EXPORT XF86ModuleData synapticsModuleData = {
 /*****************************************************************************
  *	Function Definitions
  ****************************************************************************/
+static inline void
+SynapticsCloseFd(InputInfoPtr pInfo)
+{
+    if (pInfo->fd > -1 && !(pInfo->flags & XI86_SERVER_FD)) {
+        xf86CloseSerial(pInfo->fd);
+        pInfo->fd = -1;
+    }
+}
+
 /**
  * Fill in default dimensions for backends that cannot query the hardware.
  * Eventually, we want the edges to be 1900/5400 for x, 1900/4000 for y.
@@ -877,22 +890,16 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
 
     xf86ProcessCommonOptions(pInfo, pInfo->options);
 
-    if (pInfo->fd != -1) {
-        if (priv->comm.buffer) {
-            XisbFree(priv->comm.buffer);
-            priv->comm.buffer = NULL;
-        }
-        xf86CloseSerial(pInfo->fd);
+    if (priv->comm.buffer) {
+        XisbFree(priv->comm.buffer);
+        priv->comm.buffer = NULL;
     }
-    pInfo->fd = -1;
+    SynapticsCloseFd(pInfo);
 
     return Success;
 
  SetupProc_fail:
-    if (pInfo->fd >= 0) {
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
-    }
+    SynapticsCloseFd(pInfo);
 
     if (priv->comm.buffer)
         XisbFree(priv->comm.buffer);
@@ -973,33 +980,31 @@ DeviceOn(DeviceIntPtr dev)
     }
 
     if (priv->proto_ops->DeviceOnHook &&
-        !priv->proto_ops->DeviceOnHook(pInfo, &priv->synpara)) {
-        xf86CloseSerial(pInfo->fd);
-        return !Success;
-    }
+        !priv->proto_ops->DeviceOnHook(pInfo, &priv->synpara))
+         goto error;
 
     priv->comm.buffer = XisbNew(pInfo->fd, INPUT_BUFFER_SIZE);
-    if (!priv->comm.buffer) {
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
-        return !Success;
-    }
+    if (!priv->comm.buffer)
+        goto error;
 
     xf86FlushInput(pInfo->fd);
 
     /* reinit the pad */
-    if (!QueryHardware(pInfo)) {
-        XisbFree(priv->comm.buffer);
-        priv->comm.buffer = NULL;
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
-        return !Success;
-    }
+    if (!QueryHardware(pInfo))
+        goto error;
 
     xf86AddEnabledDevice(pInfo);
     dev->public.on = TRUE;
 
     return Success;
+
+error:
+    if (priv->comm.buffer) {
+        XisbFree(priv->comm.buffer);
+        priv->comm.buffer = NULL;
+    }
+    SynapticsCloseFd(pInfo);
+    return !Success;
 }
 
 static void
@@ -1058,8 +1063,7 @@ DeviceOff(DeviceIntPtr dev)
             XisbFree(priv->comm.buffer);
             priv->comm.buffer = NULL;
         }
-        xf86CloseSerial(pInfo->fd);
-        pInfo->fd = -1;
+        SynapticsCloseFd(pInfo);
     }
     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.5.3



More information about the xorg-devel mailing list