From 1b5c4545a5dd79cbfb0364e54d05eb955b13742e Mon Sep 17 00:00:00 2001 From: Bryan Malyn Date: Thu, 22 Feb 2024 18:15:50 -0600 Subject: [PATCH] Change device scan method for v4l privacy driver --- src/blocks/privacy/v4l.rs | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/blocks/privacy/v4l.rs b/src/blocks/privacy/v4l.rs index 1b961b581e..c3934dd696 100644 --- a/src/blocks/privacy/v4l.rs +++ b/src/blocks/privacy/v4l.rs @@ -7,8 +7,6 @@ use std::path::PathBuf; use super::*; -const V4L_DEVICES_PATH: &str = "/dev/v4l/by-id"; - #[derive(Deserialize, Debug, SmartDefault)] #[serde(rename_all = "lowercase", deny_unknown_fields, default)] pub struct Config { @@ -52,33 +50,33 @@ impl<'a> Monitor<'a> { async fn update_devices(&mut self) -> Result { let mut changes = false; let mut devices_to_remove: HashMap = self.devices.clone(); - let mut sysfs_paths = read_dir(V4L_DEVICES_PATH) - .await - .error("Unable to read /dev/v4l/by-id")?; - while let Some(sysfs_path) = sysfs_paths + let mut sysfs_paths = read_dir("/dev").await.error("Unable to read /dev")?; + while let Some(entry) = sysfs_paths .next_entry() .await - .error("Unable to get next device in /dev/v4l/by-id")? + .error("Unable to get next device in /dev")? { - let sysfs_path = sysfs_path.path(); - let link_path = PathBuf::from(V4L_DEVICES_PATH) - .join(sysfs_path.read_link().error("Could not read link")?) - .canonicalize() - .error("Failed to canonicalize path")?; - - if self.config.exclude_device.contains(&link_path) { - debug!("ignoring {:?}", link_path); + if let Some(file_name) = entry.file_name().to_str() { + if !file_name.starts_with("video") { + continue; + } + } + + let sysfs_path = entry.path(); + + if self.config.exclude_device.contains(&sysfs_path) { + debug!("ignoring {:?}", sysfs_path); continue; } - if self.devices.contains_key(&link_path) { - devices_to_remove.remove(&link_path); + if self.devices.contains_key(&sysfs_path) { + devices_to_remove.remove(&sysfs_path); } else { - debug!("adding watch {:?}", link_path); + debug!("adding watch {:?}", sysfs_path); self.devices.insert( - link_path.clone(), + sysfs_path.clone(), self.watches - .add(&link_path, WatchMask::OPEN | WatchMask::CLOSE) + .add(&sysfs_path, WatchMask::OPEN | WatchMask::CLOSE) .error("Failed to watch data location")?, ); changes = true;