This is a preparation patch for adding server managed fds support.

Signed-off-by: Hans de Goede <hdego...@redhat.com>
---
 src/wcmConfig.c | 13 ++-----------
 src/xf86Wacom.c | 32 ++++++++++++++++++++++----------
 src/xf86Wacom.h |  3 +++
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index bb2c975..d19b9b4 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -601,11 +601,7 @@ static int wcmPreInit(InputDriverPtr drv, InputInfoPtr 
pInfo, int flags)
                wcmHotplugOthers(pInfo, oldname);
        }
 
-       if (pInfo->fd != -1)
-       {
-               close(pInfo->fd);
-               pInfo->fd = -1;
-       }
+       wcmClose(pInfo);
 
        /* only link them once per port. We need to try for both tablet tool
         * and touch since we do not know which tool will be added first.
@@ -623,12 +619,7 @@ SetupProc_fail:
        if (common && priv)
                common->wcmDevices = priv->next;
 
-       if (pInfo->fd != -1)
-       {
-               close(pInfo->fd);
-               pInfo->fd = -1;
-       }
-
+       wcmClose(pInfo);
        free(type);
        free(oldname);
        return BadMatch;
diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
index b0a60ff..3057d7a 100644
--- a/src/xf86Wacom.c
+++ b/src/xf86Wacom.c
@@ -55,6 +55,10 @@
 #define XIGetKnownProperty(prop) 0
 #endif
 
+#ifndef XI86_SERVER_FD
+#define XI86_SERVER_FD 0x20
+#endif
+
 static int wcmDevOpen(DeviceIntPtr pWcm);
 static int wcmReady(InputInfoPtr pInfo);
 static void wcmDevReadInput(InputInfoPtr pInfo);
@@ -544,6 +548,22 @@ Bool wcmOpen(InputInfoPtr pInfo)
 }
 
 /*****************************************************************************
+ * wcmClose --
+ ****************************************************************************/
+
+void wcmClose(InputInfoPtr pInfo)
+{
+       WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
+
+       DBG(1, priv, "closing device file\n");
+
+       if (pInfo->fd > -1 && !(pInfo->flags & XI86_SERVER_FD)) {
+               xf86CloseSerial(pInfo->fd);
+               pInfo->fd = -1;
+       }
+}
+
+/*****************************************************************************
  * wcmDevOpen --
  *    Open the physical device and init information structs.
  ****************************************************************************/
@@ -564,12 +584,7 @@ static int wcmDevOpen(DeviceIntPtr pWcm)
                if ((wcmOpen (pInfo) != Success) || !common->device_path)
                {
                        DBG(1, priv, "Failed to open device (fd=%d)\n", 
pInfo->fd);
-                       if (pInfo->fd >= 0)
-                       {
-                               DBG(1, priv, "Closing device\n");
-                               xf86CloseSerial(pInfo->fd);
-                       }
-                       pInfo->fd = -1;
+                       wcmClose(pInfo);
                        return FALSE;
                }
 
@@ -745,10 +760,7 @@ static void wcmDevClose(InputInfoPtr pInfo)
        {
                pInfo->fd = -1;
                if (!--common->fd_refs)
-               {
-                       DBG(1, common, "Closing device; uninitializing.\n");
-                       xf86CloseSerial (common->fd);
-               }
+                       wcmClose(pInfo);
        }
 }
 
diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
index c0448f2..882d8cd 100644
--- a/src/xf86Wacom.h
+++ b/src/xf86Wacom.h
@@ -106,6 +106,9 @@ struct _WacomModule
 /* Open the device with the right serial parmeters */
 extern Bool wcmOpen(InputInfoPtr pInfo);
 
+/* Close the device */
+extern void wcmClose(InputInfoPtr pInfo);
+
 /* device autoprobing */
 char *wcmEventAutoDevProbe (InputInfoPtr pInfo);
 
-- 
1.9.0

_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to