diff --git a/.libusbx.metadata b/.libusbx.metadata new file mode 100644 index 0000000..9daa697 --- /dev/null +++ b/.libusbx.metadata @@ -0,0 +1 @@ +1ca868f775093b0109d9240cb3ccd36367764dc6 SOURCES/libusbx-1.0.15.tar.bz2 diff --git a/README.md b/README.md deleted file mode 100644 index 0e7897f..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -The master branch has no content - -Look at the c7 branch if you are working with CentOS-7, or the c4/c5/c6 branch for CentOS-4, 5 or 6 - -If you find this file in a distro specific branch, it means that no content has been checked in yet diff --git a/SOURCES/0001-linux_usbfs-Work-around-a-driver-binding-race-in-res.patch b/SOURCES/0001-linux_usbfs-Work-around-a-driver-binding-race-in-res.patch new file mode 100644 index 0000000..3a39c1c --- /dev/null +++ b/SOURCES/0001-linux_usbfs-Work-around-a-driver-binding-race-in-res.patch @@ -0,0 +1,86 @@ +From 78a150bfbbd84eb524e878bf05101c1ad2eac0b8 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Fri, 6 Jul 2012 14:35:53 +0200 +Subject: [PATCH 3/3] linux_usbfs: Work around a driver binding race in reset + handling + +I've been seeing these intermittent failures to reclaim an interface after +a device reset. After much debugging and inserting sleeps in strategic +places to make the race window larger I've found the following race: +1) A user is running some software using libusb which will automatically + detect, and "bind" to, any newly plugged in USB-devices. For example + a virtual machine viewer with automatic USB-redirection +2) The user plugs in a new usb-storage device +3) The usb-storage driver is not yet loaded, udev spawns + "modprobe usb-storage", this blocks on disk-io +4) The libusb app opens the device, claims all interfaces, does a device-reset +5) While the IOCTL_USBFS_RESET is running the modprobe completes +6) The driver registration blocks on an USB lock held by the reset code path +7) When the reset finishes the driver registration completes and the driver + binds itself to the device, before IOCTL_USBFS_RESET returns to userspace +8) libusb tries to re-claim all interfaces it had claimed before the reset +9) libusb fails as usb-storage is now bound to it + +This patch works around this issue by simply unbinding the driver for all +interfaces which were claimed before the reset. Normally this is a no-op as +no driver (other then usbfs) can be bound for claimed interfaces before the +reset. + +But as the above example shows, the exception is a driver completing +registration, and as part of this binding to any elegible devices, between +IOCTL_USBFS_RESET and our re-claiming of the interface. The largest part +of the race window here is the time IOCTL_USBFS_RESET takes, as that does a +fair amount of IO with the device. This part of the race window is +worked around by this patch. + +This still leaves a theoretical race window where the driver registration +finishes between our driver-unbind and interface-reclaim, I'm afraid there +is nothing we can against this. + +This patch also improves the error logging, and makes libusb_device_reset +properly return an error when re-claiming fails. + +Signed-off-by: Hans de Goede +--- + libusb/os/linux_usbfs.c | 14 +++++++++++++- + 1 file changed, 13 insertions(+), 1 deletion(-) + +diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c +index 3894554..10d138a 100644 +--- a/libusb/os/linux_usbfs.c ++++ b/libusb/os/linux_usbfs.c +@@ -108,6 +108,9 @@ static int sysfs_can_relate_devices = 0; + /* do we have a descriptors file? */ + static int sysfs_has_descriptors = 0; + ++static int op_detach_kernel_driver(struct libusb_device_handle *handle, ++ int interface); ++ + struct linux_device_priv { + char *sysfs_dir; + unsigned char *dev_descriptor; +@@ -1497,11 +1500,20 @@ static int op_reset_device(struct libusb_device_handle *handle) + /* And re-claim any interfaces which were claimed before the reset */ + for (i = 0; i < USB_MAXINTERFACES; i++) { + if (handle->claimed_interfaces & (1L << i)) { ++ /* ++ * A driver may have completed modprobing during ++ * IOCTL_USBFS_RESET, and bound itself as soon as ++ * IOCTL_USBFS_RESET released the device lock ++ */ ++ op_detach_kernel_driver(handle, i); ++ + r = op_claim_interface(handle, i); + if (r) { + usbi_warn(HANDLE_CTX(handle), +- "failed to re-claim interface %d after reset", i); ++ "failed to re-claim interface %d after reset: %s", ++ i, libusb_error_name(r)); + handle->claimed_interfaces &= ~(1L << i); ++ ret = LIBUSB_ERROR_NOT_FOUND; + } + } + } +-- +1.7.11.2 + diff --git a/SPECS/libusbx.spec b/SPECS/libusbx.spec new file mode 100644 index 0000000..a951f43 --- /dev/null +++ b/SPECS/libusbx.spec @@ -0,0 +1,116 @@ +Summary: Library for accessing USB devices +Name: libusbx +Version: 1.0.15 +Release: 2%{?dist} +Source0: http://downloads.sourceforge.net/libusbx/libusbx-%{version}.tar.bz2 +Patch1: 0001-linux_usbfs-Work-around-a-driver-binding-race-in-res.patch +License: LGPLv2+ +Group: System Environment/Libraries +URL: http://sourceforge.net/apps/mediawiki/libusbx/ +BuildRequires: doxygen +Provides: libusb1 = %{version}-%{release} +Obsoletes: libusb1 <= 1.0.9 + +%description +This package provides a way for applications to access USB devices. + +Libusbx is a fork of the original libusb, which is a fully API and ABI +compatible drop in for the libusb-1.0.9 release. The libusbx fork was +started by most of the libusb-1.0 developers, after the original libusb +project did not produce a new release for over 18 months. + +Note that this library is not compatible with the original libusb-0.1 series, +if you need libusb-0.1 compatibility install the libusb package. + + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries +Requires: %{name}%{?_isa} = %{version}-%{release} +Provides: libusb1-devel = %{version}-%{release} +Obsoletes: libusb1-devel <= 1.0.9 + +%description devel +The %{name}-devel package contains libraries and header files for +developing applications that use %{name}. + + +%package devel-doc +Summary: Development files for %{name} +Group: Development/Libraries +Provides: libusb1-devel-doc = %{version}-%{release} +Obsoletes: libusb1-devel-doc <= 1.0.9 +BuildArch: noarch + +%description devel-doc +This package contains API documentation for %{name}. + + +%prep +%setup -q +%patch1 -p1 + + +%build +%configure --disable-static --enable-examples-build +make %{?_smp_mflags} +pushd doc +make docs +popd + + +%install +make install DESTDIR=$RPM_BUILD_ROOT +rm $RPM_BUILD_ROOT%{_libdir}/*.la + + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + + +%files +%doc AUTHORS COPYING README ChangeLog +%{_libdir}/*.so.* + +%files devel +%{_includedir}/libusb-1.0 +%{_libdir}/*.so +%{_libdir}/pkgconfig/libusb-1.0.pc + +%files devel-doc +%doc doc/html examples/*.c + + +%changelog +* Fri Apr 19 2013 Hans de Goede - 1.0.15-2 +- Replace tarbal with upstream re-spun tarbal which fixes line-ending and + permission issues + +* Wed Apr 17 2013 Hans de Goede - 1.0.15-1 +- Upgrade to 1.0.15 (rhbz#952575) + +* Tue Apr 2 2013 Hans de Goede - 1.0.14-3 +- Drop devel-doc Requires from the devel package (rhbz#947297) + +* Thu Feb 14 2013 Fedora Release Engineering - 1.0.14-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild + +* Wed Sep 26 2012 Hans de Goede - 1.0.14-1 +- Upgrade to 1.0.14 + +* Mon Sep 24 2012 Hans de Goede - 1.0.13-1 +- Upgrade to 1.0.13 + +* Thu Jul 19 2012 Fedora Release Engineering - 1.0.11-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild + +* Wed May 23 2012 Hans de Goede - 1.0.11-2 +- Fix URL to actually point to libusbx +- Improve description to explain the relation between libusbx and libusb +- Build the examples (to test linking, they are not packaged) + +* Tue May 22 2012 Hans de Goede - 1.0.11-1 +- New libusbx package, replacing libusb1 +- Switching to libusbx upstream as that actually does releases (hurray) +- Drop all patches (all upstream) +- Drop -static subpackage (there are no packages using it)