lib: don't detach kernel driver by default

Since this feature also disconnects running instances
of librtlsdr that claimed the device, it is now disabled
by default and can only be enabled at compile time.

To enable it when building with cmake:
cmake . -DDETACH_KERNEL_DRIVER=ON

To enable it when building with automake:
./configure --enable-driver-detach

Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
Steve Markgraf
2013-06-04 14:47:16 +02:00
parent ce341fe53b
commit 3e17ef2b55
3 changed files with 26 additions and 0 deletions

View File

@ -1351,12 +1351,22 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
if (libusb_kernel_driver_active(dev->devh, 0) == 1) {
dev->driver_active = 1;
#ifdef DETACH_KERNEL_DRIVER
if (!libusb_detach_kernel_driver(dev->devh, 0)) {
fprintf(stderr, "Detached kernel driver\n");
} else {
fprintf(stderr, "Detaching kernel driver failed!");
goto err;
}
#else
fprintf(stderr, "\nKernel driver is active, or device is "
"claimed by second instance of librtlsdr."
"\nIn the first case, please either detach"
" or blacklist the kernel module\n"
"(dvb_usb_rtl28xxu), or enable automatic"
" detaching at compile time.\n\n");
#endif
}
r = libusb_claim_interface(dev->devh, 0);
@ -1484,12 +1494,14 @@ int rtlsdr_close(rtlsdr_dev_t *dev)
libusb_release_interface(dev->devh, 0);
#ifdef DETACH_KERNEL_DRIVER
if (dev->driver_active) {
if (!libusb_attach_kernel_driver(dev->devh, 0))
fprintf(stderr, "Reattached kernel driver\n");
else
fprintf(stderr, "Reattaching kernel driver failed!\n");
}
#endif
libusb_close(dev->devh);