make find-device-port-linux-udev more friendly

Add some helpful debugging, and if there is a risk of contention
with ModemManager, provide some helpful advice.
pull/304/head
Adam Spiers 7 years ago
parent dd1aca0f13
commit 980d703f5e

@ -2,6 +2,9 @@
use warnings;
use strict;
use FindBin qw{$Bin};
die "Usage: $0 VID PID\n" unless @ARGV == 2;
my $vid = shift;
@ -10,8 +13,16 @@ my $prefix = '/dev/serial/by-id/';
my @paths = `ls $prefix`;
my %devices;
sub debug {
print STDERR @_;
}
debug "Looking for USB device with vid=$vid and pid=$pid\n";
for my $path (@paths) {
chomp($path);
debug "Examining $path\n";
debug " not symlink\n" unless -l $prefix . $path;
next unless -l $prefix . $path;
my @data = `udevadm info -q property --name=${prefix}${path}`;
for my $line (@data) {
@ -19,15 +30,36 @@ for my $path (@paths) {
my ( $key, $val ) = split( /=/, $line, 2 );
$devices{$path}{$key} = $val;
}
if ( ( hex $devices{$path}{'ID_VENDOR_ID'} == hex $vid )
&& ( hex $devices{$path}{'ID_MODEL_ID'} == hex $pid ) )
{
if ( hex $devices{$path}{'ID_VENDOR_ID'} != hex $vid ) {
debug " ID_VENDOR_ID $devices{$path}{'ID_VENDOR_ID'} != $vid\n";
next;
}
if ( hex $devices{$path}{'ID_MODEL_ID'} != hex $pid ) {
debug " ID_MODEL_ID $devices{$path}{'ID_MODEL_ID'} != $pid\n";
next;
}
if ( $devices{$path}{'ID_MM_CANDIDATE'} ) {
warn "Yikes. ModemManager wants to pwn your keyboard";
}
debug " Found keyboard!\n";
print $devices{$path}{DEVNAME};
exit(0);
if ( $devices{$path}{'ID_MM_DEVICE_IGNORE'} ) {
debug " ID_MM_DEVICE_IGNORE is set - good!\n";
}
if ( $devices{$path}{'ID_MM_CANDIDATE'}) {
my $rules = "$Bin/../etc/99-kaleidoscope.rules";
debug <<EOWARN
WARNING: your udev rules are currently configured to suggest
that your keyboard is suitable for use by ModemManager. This
means that there is a risk of ModemManager interfering. To avoid
this, copy
$rules
to /etc/udev/rules.d
EOWARN
}
print $devices{$path}{DEVNAME};
exit(0);
}

Loading…
Cancel
Save