On Fri, Nov 25, 2011 at 12:35:06AM +0530, Aruna Balakrishaiah wrote: > > 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. Have you ever seen this error before? As package-maintainer in a number of distros for this package, no one has ever complained about it before. And I do think that the program should return an error if there are no USB devices present, that means something is wrong and is easier to check for, right? > > +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. Ok, why not change libusb to properly handle this if it's really a big deal. Wouldn't all of the packages that use also have this same issue? > > - 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. But are you sure that your check_for_usbdevice() will actually work properly for all distros and kernel versions (hint, I don't think so...) libusb has this logic already in it, I do not want to duplicate it again, that's why we use the library. And yes, I do consider the fact that if you run lsusb on a system with no usb devices, it should return an error, just like I also think lspci does the same thing, right? thanks, 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