On Wed, Nov 23, 2011 at 10:32:33PM +0530, Aruna Balakrishnaiah wrote: > Signed-off-by: Aruna Balakrishnaiah <aruna@xxxxxxxxxxxxxxxxxx> > > 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? > --- > 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. > + > /* ---------------------------------------------------------------------- */ > > 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? greg k-h -- 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