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 stating no USB devices found and returns exit status of 0 --- lsusb.c | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/lsusb.c b/lsusb.c index 37c43f7..f2a9a6c 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,26 @@ static int treedump(void) return 0; } +static int is_usbdevice(void) +{ + struct dirent *d; + int n = 0; + DIR *dir = opendir(sysbususb); + + if (dir == NULL) + return 0; + + while ((d = readdir(dir)) != NULL) { + if (++n > 2) + break; + } + + closedir(dir); + + return n > 2; + +} + /* ---------------------------------------------------------------------- */ int main(int argc, char *argv[]) @@ -4027,6 +4049,11 @@ int main(int argc, char *argv[]) strerror(err)); status = 0; + if (!is_usbdevice()) { + fprintf(stdout, "No USB devices found\n"); + return 0; + } + err = libusb_init(&ctx); if (err) { fprintf(stderr, "unable to initialize libusb: %i\n", err); -- 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