Skip to content

Commit

Permalink
Workaround for bug #226
Browse files Browse the repository at this point in the history
Update `eruption-debug-tool` code
  • Loading branch information
X3n0m0rph59 committed Sep 1, 2023
1 parent 903192d commit de01f9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
34 changes: 23 additions & 11 deletions eruption-debug-tool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,29 +230,41 @@ pub fn udev_inhibited_workaround(
product_id: u16,
interface_num: i32,
) -> Result<()> {
let interface_num_str = format!("{interface_num:02}");
let interface_num_osstr = OsStr::new(&interface_num_str);

let mut enumerator = udev::Enumerator::new()?;
enumerator.match_subsystem("input")?;
enumerator.match_property("ID_VENDOR_ID", format!("{vendor_id:04x}"))?;
enumerator.match_property("ID_MODEL_ID", format!("{product_id:04x}"))?;
enumerator.match_property("ID_USB_INTERFACE_NUM", &interface_num_str)?;
enumerator.match_attribute("inhibited", "0")?;

// the following filters seem to not work reliably, using udev crate version 0.7

// enumerator.match_subsystem("input")?;
// enumerator.match_property("ID_VENDOR_ID", format!("{vendor_id:04x}"))?;
// enumerator.match_property("ID_MODEL_ID", format!("{product_id:04x}"))?;
// enumerator.match_property("ID_USB_INTERFACE_NUM", &interface_num_str)?;
// enumerator.match_attribute("inhibited", "0")?;

// ... we have to check them manually in find(..) for now

enumerator
.scan_devices()?
.find(|dev| {
// For some reason, the above match_property() still brings back devices with different interface_nums, so filter again.
dev.property_value("ID_USB_INTERFACE_NUM")
.map_or(false, |value| value == interface_num_osstr)
dev.property_value("ID_VENDOR_ID").map_or(false, |value| {
value == OsStr::new(&format!("{vendor_id:04x}"))
}) && dev.property_value("ID_MODEL_ID").map_or(false, |value| {
value == OsStr::new(&format!("{product_id:04x}"))
}) && dev
.property_value("ID_USB_INTERFACE_NUM")
.map_or(false, |value| {
value == OsStr::new(&format!("{interface_num:02}"))
})
&& dev
.attribute_value("inhibited")
.map_or(false, |value| value == OsStr::new("0"))
})
.map_or_else(
|| Err(eyre!("Udev device not found.")),
|mut dev| {
// Toggling the value on and off is enough to quiet spurious events.
dev.set_attribute_value("inhibited", "1")?;
dev.set_attribute_value("inhibited", "0")?;

Ok(())
},
)
Expand Down
6 changes: 3 additions & 3 deletions eruption/src/hwdevices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ pub fn udev_inhibited_workaround(
.map_or_else(
|| Err(eyre!("Udev device not found.")),
|mut dev| {
info!("Trying to apply Udev 'inhibited' workaround for device {vendor_id:04x}:{product_id:04x} iface:{interface_num:02}");
info!("Trying to apply Udev \"inhibited\" workaround for device {vendor_id:04x}:{product_id:04x} iface:{interface_num:02}");

// Toggling the value on and off is enough to quiet spurious events.
dev.set_attribute_value("inhibited", "1")?;
Expand All @@ -2131,9 +2131,9 @@ pub fn attempt_udev_inhibited_workaround(vendor_id: u16, product_id: u16, interf
let workaround_attempt = udev_inhibited_workaround(vendor_id, product_id, interface_num);
if let Err(err) = workaround_attempt {
warn!(
"Udev 'inhibited' workaround for device {vendor_id:04x}:{product_id:04x} iface:{interface_num:02} failed: {err}");
"Udev \"inhibited\" workaround for device {vendor_id:04x}:{product_id:04x} iface:{interface_num:02} failed: {err}");
} else {
info!("Udev 'inhibited' workaround succeeded for device {vendor_id:04x}:{product_id:04x} iface:{interface_num:02}");
info!("Udev \"inhibited\" workaround succeeded for device {vendor_id:04x}:{product_id:04x} iface:{interface_num:02}");
}
}

Expand Down

0 comments on commit de01f9f

Please sign in to comment.