Re: fix for lsusb:unable to initialize libusb: -99

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Greg,

I had not received this mail,  got it from mailing list archive. Please
find my answers below.

On Wed, Nov 23, 2011 at 10:32:33PM +0530, Aruna Balakrishnaiah wrote:
> Signed-off-by: Aruna Balakrishnaiah <aruna@...>
>
>    lsusb throws unusual error message "unable to initialize libusb: -99"

> with exit status of 1 when usb devices are not listed. Patch handles it
> without printing anything and returns exit status of 0.

>Why would we want to return "good" if there was an error?

 Since there are no usb devices in the system , it should exit saying no
USB devices or something similar to it. Throwing message about failure of
initialization of libusb may lead to confusion among users and it might not
be their concern. for example: ls on an empty directory will return with an
exit status of 0 itself. It is not treated as an error.

> ---
>  lsusb.c |   27 ++++++++++++++++++++++++++-
>  1 files changed, 26 insertions(+), 1 deletions(-)
>
> diff --git a/lsusb.c b/lsusb.c
> index 37c43f7..081d42e 100644
> --- a/lsusb.c
> +++ b/lsusb.c
> @@ -44,6 +44,7 @@
>  #include "usbmisc.h"
>
>  #include <getopt.h>
> +#include <dirent.h>
>
>  #define le16_to_cpu(x) libusb_cpu_to_le16(libusb_cpu_to_le16(x))
>
> @@ -108,6 +109,7 @@
>  #define		 HUB_STATUS_BYTELEN		 3		 /* max 3 bytes status =
hub + 23 ports */
>
>  static const char procbususb[] = "/proc/bus/usb";
> +static const char sysbususb[] = "/sys/bus/usb/devices";
>  static unsigned int verblevel = VERBLEVEL_DEFAULT;
>  static int do_report_desc = 1;
>  static const char * const encryption_type[] = {
> @@ -3920,6 +3922,25 @@ static int treedump(void)
>  		 return 0;
>  }
>
> +static int check_for_usbdevice(void)
> +{
> +		 struct dirent *d;
> +		 int n = 0;
> +		 DIR *dir = opendir(sysbususb);
> +
> +		 while ((d = readdir(dir)) != NULL) {
> +		 		 if (++n > 2)
> +		 		 		 break;
> +		 }
> +
> +		 closedir(dir);
> +
> +		 if (n <= 2)
> +		 		 return 1;
> +		 else
> +		 		 return 0;
> +}

>No, we don't want to be doing this, this is why we use libusb, it
>handles this type of thing for us.

Since libusb_init returns error codes , we would need a seperate function
to check for usb devices.

> +
>  /*
---------------------------------------------------------------------- */
>
>  int main(int argc, char *argv[])
> @@ -4027,7 +4048,11 @@ int main(int argc, char *argv[])
>  		 		 		 		 strerror(err));
>  		 status = 0;
>
> -		 err = libusb_init(&ctx);
> +		 if (check_for_usbdevice())
> +		 		 return 0;

>Again, returning 0 for when there is an error is not a good idea.

>Why is the existing code somehow not working properly for you?  When
>USB devices can't be found, it's good to return an error, right?

As mentioned issuing ls on an empty directory cant be treated as an error
right?User might not be concerned about libusb library. Since the command
is not failing its just there are no USB devices to list.

>greg k-h

Thanks,
Aruna,

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux