Skip to content

Commit

Permalink
tlp-usblist: harden lsusb output parser
Browse files Browse the repository at this point in the history
Reference:
* #760 (comment)
  • Loading branch information
linrunner committed Sep 12, 2024
1 parent ea8e2bd commit fc3b3d1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tlp-usblist
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ foreach my $udev (grep { ! /:/ } glob USBD . "/*") {
# Output device list with attributes and drivers
foreach (`lsusb 2> /dev/null`) {
my ($bus, $dev, $usbid, $desc) = /Bus (\S+) Device (\S+): ID (\S+)[ ]+(.*)/;
my $usbk = $bus . "_" . $dev;
$desc =~ s/\s+$//;
$desc ||= "<unknown>";
print "Bus $bus Device $dev ID $usbid $usbdevices{$usbk}[1] -- $desc ("
. usbdriverlist ($usbdevices{$usbk}[0]) . ")\n";
if (length ($bus) and length ($dev) and length ($usbid) ) {
my $usbk = $bus . "_" . $dev;
$desc =~ s/\s+$//;
$desc ||= "<unknown>";
print "Bus $bus Device $dev ID $usbid $usbdevices{$usbk}[1] -- $desc ("
. usbdriverlist($usbdevices{$usbk}[0]) . ")\n";
}
}

exit 0;

0 comments on commit fc3b3d1

Please sign in to comment.