Instead of having every function open and close the fd, just open it once towards the start of PreInit and then close it at the end again. Anything it between can just re-use it.
This reshuffles some of the code in PreInit that was supposedly working when "auto-dev" was set. It wasn't, so this just emphasises the brokenness. Signed-off-by: Peter Hutterer <[email protected]> --- src/wcmConfig.c | 33 ++++++++++++++++++++++++++------- src/wcmValidateDevice.c | 34 ---------------------------------- 2 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/wcmConfig.c b/src/wcmConfig.c index ef477e8..75e382c 100644 --- a/src/wcmConfig.c +++ b/src/wcmConfig.c @@ -25,6 +25,7 @@ #include "wcmFilter.h" #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> /***************************************************************************** * wcmAllocate -- @@ -63,7 +64,6 @@ static int wcmAllocate(LocalDevicePtr local, char* type_name, int flag) local->control_proc = gWacomModule.DevChangeControl; local->close_proc = gWacomModule.DevClose; local->switch_mode = gWacomModule.DevSwitchMode; - local->fd = -1; local->atom = 0; local->dev = NULL; local->private = priv; @@ -340,16 +340,24 @@ static LocalDevicePtr wcmPreInit(InputDriverPtr drv, IDevPtr dev, int flags) */ xf86CollectInputOptions(local, default_options, NULL); - /* initialize supported keys */ - wcmDeviceTypeKeys(local, keys, &tablet_id); - device = xf86SetStrOption(local->options, "Device", NULL); type = xf86FindOptionValue(local->options, "Type"); - need_hotplug = wcmNeedAutoHotplug(local, &type, keys); /* leave the undefined for auto-dev (if enabled) to deal with */ - if(device) + if (device) { + SYSCALL(local->fd = open(device, O_RDONLY)); + if (local->fd < 0) + { + xf86Msg(X_WARNING, "%s: failed to open %s.\n", + local->name, device); + goto SetupProc_fail; + } + + /* initialize supported keys */ + wcmDeviceTypeKeys(local, keys, &tablet_id); + need_hotplug = wcmNeedAutoHotplug(local, &type, keys); + /* check if the type is valid for those don't need hotplug */ if(!need_hotplug && !wcmIsAValidType(type, keys)) goto SetupProc_fail; @@ -407,7 +415,12 @@ static LocalDevicePtr wcmPreInit(InputDriverPtr drv, IDevPtr dev, int flags) wcmHotplugOthers(local, keys); } - /* return the LocalDevice */ + if (local->fd != -1) + { + close(local->fd); + local->fd = -1; + } + return (local); SetupProc_fail: @@ -415,6 +428,12 @@ SetupProc_fail: xfree(priv); if (local) { + if (local->fd != -1) + { + close(local->fd); + local->fd = -1; + } + local->private = NULL; xf86DeleteInput(local, 0); } diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c index 86a6351..40bb677 100644 --- a/src/wcmValidateDevice.c +++ b/src/wcmValidateDevice.c @@ -84,22 +84,9 @@ int wcmIsDuplicate(char* device, LocalDevicePtr local) int isInUse = 0; char* lsource = xf86CheckStrOption(local->options, "_source", ""); - local->fd = -1; - /* always allow xorg.conf defined tools to be added */ if (!strlen(lsource)) goto ret; - /* open the port */ - SYSCALL(local->fd = open(device, O_RDONLY, 0)); - if (local->fd < 0) - { - /* can not open the device */ - xf86Msg(X_ERROR, "%s: Unable to open Wacom device \"%s\".\n", - local->name, device); - isInUse = 1; - goto ret; - } - if (fstat(local->fd, &st) == -1) { /* can not access major/minor to check device duplication */ @@ -127,11 +114,6 @@ int wcmIsDuplicate(char* device, LocalDevicePtr local) isInUse = 4; } ret: - if (local->fd >= 0) - { - close(local->fd); - local->fd = -1; - } return isInUse; } @@ -174,28 +156,12 @@ int wcmDeviceTypeKeys(LocalDevicePtr local, unsigned long* keys, int* tablet_id) { int ret = 1; - int fd = -1; - char* device; - - device = xf86SetStrOption(local->options, "Device", NULL); - - SYSCALL(fd = open(device, O_RDONLY)); - if (fd < 0) - { - xf86Msg(X_WARNING, "%s: failed to open %s in " - "wcmDeviceTypeKeys.\n", local->name, device); - return 0; - } - - local->fd = fd; /* serial ISDV4 devices */ *tablet_id = isdv4ProbeKeys(local, keys); if (!*tablet_id) /* USB devices */ *tablet_id = usbProbeKeys(local, keys); - close(fd); - local->fd = -1; return ret; } -- 1.6.6.1 ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Linuxwacom-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel
