Improve libusb's error code for permission issues.

libusb on my Linux box is returning EACCES error when invalid
permissions exist.  Modify open to translate that into
SANE_STATUS_ECCESS_DENIED since that error description is
used for this case.

Modify sanei_usb_test.c to not treat access denied or busy
error codes as real failures since its expected to occur on
boxes that USB device is already claimed by another driver
and if that device uses default root only permissions.
merge-requests/1/head
Chris Bagwell 2013-08-26 21:21:20 -05:00
rodzic a4bfd6da07
commit af10791227
3 zmienionych plików z 50 dodań i 20 usunięć

Wyświetl plik

@ -1,3 +1,12 @@
2013-08-26 Chris Bagwell <chris@cnpbagwell.com>
* sanei/sanei_usb.c: Treat errno of EACCES as access denied.
This is what libusb is return on my Linux box. This will help
give more helpful error messages to user during debugging.
* testsuite/sanie/sanie_usb_test.c: Do not treat open failures
because of permission errors or already opened by other processes
as test failures since this is expected in some cases (such as
network devices that use vendor specific class).
2013-08-16 Chris Bagwell <chris@cnpbagwell.com>
* testsuite/sanei/Makefile.am: Add missing data files to distribution.
Pass in $srcdir to sanei_config_test so it knows were data files are

Wyświetl plik

@ -1352,7 +1352,7 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn)
DBG (1, "sanei_usb_open: can't open device `%s': %s\n",
devname, strerror (errno));
if (errno == EPERM)
if (errno == EPERM || errno == EACCES)
{
DBG (1, "Make sure you run as root or set appropriate "
"permissions\n");
@ -1389,7 +1389,7 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn)
SANE_Status status = SANE_STATUS_INVAL;
DBG (1, "sanei_usb_open: libusb complained: %s\n", usb_strerror ());
if (errno == EPERM)
if (errno == EPERM || errno == EACCES)
{
DBG (1, "Make sure you run as root or set appropriate "
"permissions\n");
@ -1416,7 +1416,7 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn)
SANE_Status status = SANE_STATUS_INVAL;
DBG (1, "sanei_usb_open: libusb complained: %s\n", usb_strerror ());
if (errno == EPERM)
if (errno == EPERM || errno == EACCES)
{
DBG (1, "Make sure you run as root or set appropriate "
"permissions\n");

Wyświetl plik

@ -268,13 +268,11 @@ test_store_device (void)
return 1;
}
/** count opened devices
* count all opended devices and check it against expected value
* @param expected use opened count
* @return 1 on success, else 0
/** return count of opened devices
* @return count of opened devices
*/
static int
count_opened (int expected)
get_opened (void)
{
int num = 0;
int i;
@ -287,6 +285,19 @@ count_opened (int expected)
num++;
}
}
return num;
}
/** count opened devices
* count all opended devices and check it against expected value
* @param expected use opened count
* @return 1 on success, else 0
*/
static int
count_opened (int expected)
{
int num = get_opened();
if (num != expected)
{
printf ("ERROR: %d opened devices, expected %d!\n", num, expected);
@ -325,9 +336,17 @@ test_open_all (SANE_Int * dn, int expected)
}
else
{
printf ("ERROR: couldn't open device %s!\n",
devices[i].devname);
return 0;
if (status == SANE_STATUS_ACCESS_DENIED ||
status == SANE_STATUS_DEVICE_BUSY)
{
expected--;
}
else
{
printf ("ERROR: couldn't open device %s!\n",
devices[i].devname);
return 0;
}
}
}
}
@ -810,7 +829,7 @@ test_attach (void)
int
main (int argc, char **argv)
{
int detected, i;
int detected, opened, i;
SANE_Int dn[MAX_DEVICES];
#ifdef HAVE_LIBUSB
@ -858,8 +877,10 @@ main (int argc, char **argv)
/* open all available devices */
assert (test_open_all (dn, detected));
opened = get_opened();
/* rescan devices : detected and opened count shouldn't change */
assert (test_scan_devices (detected, detected));
assert (test_scan_devices (detected, opened));
/* try to open an inexisting device */
assert (test_open_invalid ());
@ -870,26 +891,26 @@ main (int argc, char **argv)
/* there should be still as many detected devices */
assert (count_detected (detected));
/* there should be still as many opened devices than detected devices */
assert (count_opened (detected));
/* there should be still as many opened devices */
assert (count_opened (opened));
assert (test_exit (1));
/* there should be still as many opened devices than detected devices */
assert (count_opened (detected));
/* there should be still as many opened devices */
assert (count_opened (opened));
/* count devices again , sanei_usb_exit() shouldn't have
* change the count */
assert (count_detected (detected));
/* claim all available devices */
assert (test_claim_all (dn, detected));
assert (test_claim_all (dn, opened));
/* then release them all */
assert (test_release_all (dn, detected));
assert (test_release_all (dn, opened));
/* close all opened devices */
assert (test_close_all (dn, detected));
assert (test_close_all (dn, opened));
/* check there is no opened device */
assert (count_opened (0));