Refactor UdevAdapter to remove udev monitor fallback and update PKGBUILD for consistent naming
This commit is contained in:
parent
a2b7391a71
commit
c5102639f4
2 changed files with 4 additions and 72 deletions
|
|
@ -52,12 +52,6 @@ impl Adapter for UdevAdapter {
|
||||||
|
|
||||||
async fn run(&self, tx: mpsc::Sender<RawEvent>) -> Result<()> {
|
async fn run(&self, tx: mpsc::Sender<RawEvent>) -> Result<()> {
|
||||||
debug!("udev adapter started");
|
debug!("udev adapter started");
|
||||||
match run_udev_monitor(self.subsystems.clone(), tx.clone()).await {
|
|
||||||
Ok(()) => return Ok(()),
|
|
||||||
Err(err) => {
|
|
||||||
tracing::warn!(error = %err, "udev netlink monitor unavailable, falling back to sysfs polling (add user to 'plugdev' group for real-time events)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: poll sysfs every 2 seconds for environments where the
|
// Fallback: poll sysfs every 2 seconds for environments where the
|
||||||
// netlink socket is unavailable (missing plugdev membership, containers, etc).
|
// netlink socket is unavailable (missing plugdev membership, containers, etc).
|
||||||
|
|
@ -103,67 +97,6 @@ struct ScannedDevice {
|
||||||
subsystem: String,
|
subsystem: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_udev_monitor(subsystems: Vec<String>, tx: mpsc::Sender<RawEvent>) -> Result<()> {
|
|
||||||
tokio::task::spawn_blocking(move || -> Result<()> {
|
|
||||||
let mut builder = udev::MonitorBuilder::new()?;
|
|
||||||
for subsystem in &subsystems {
|
|
||||||
builder = builder.match_subsystem(subsystem)?;
|
|
||||||
}
|
|
||||||
let monitor = builder.listen()?;
|
|
||||||
|
|
||||||
for event in monitor.iter() {
|
|
||||||
let action = event
|
|
||||||
.action()
|
|
||||||
.map(|a| a.to_string_lossy().to_string())
|
|
||||||
.unwrap_or_else(|| "change".to_string());
|
|
||||||
let subsystem = event
|
|
||||||
.subsystem()
|
|
||||||
.map(|s| s.to_string_lossy().to_string())
|
|
||||||
.unwrap_or_else(|| "unknown".to_string());
|
|
||||||
let name = event
|
|
||||||
.property_value("ID_MODEL")
|
|
||||||
.or_else(|| event.property_value("NAME"))
|
|
||||||
.map(|v| v.to_string_lossy().to_string())
|
|
||||||
.or_else(|| event.devnode().map(|n| n.display().to_string()))
|
|
||||||
.unwrap_or_else(|| "unknown".to_string());
|
|
||||||
let id = event
|
|
||||||
.syspath()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let msg = RawEvent {
|
|
||||||
source: AdapterSource::Udev,
|
|
||||||
kind: "udev.change".to_string(),
|
|
||||||
payload: json!({
|
|
||||||
"action": action,
|
|
||||||
"id": id,
|
|
||||||
"name": name,
|
|
||||||
"subsystem": subsystem,
|
|
||||||
"id_input_keyboard": prop_bool(&event, "ID_INPUT_KEYBOARD"),
|
|
||||||
"id_input_mouse": prop_bool(&event, "ID_INPUT_MOUSE"),
|
|
||||||
"id_input_joystick": prop_bool(&event, "ID_INPUT_JOYSTICK"),
|
|
||||||
"id_input_touchpad": prop_bool(&event, "ID_INPUT_TOUCHPAD"),
|
|
||||||
"id_input_tablet": prop_bool(&event, "ID_INPUT_TABLET"),
|
|
||||||
"id_usb_class": prop_str(&event, "ID_USB_CLASS"),
|
|
||||||
"id_usb_interfaces": prop_str(&event, "ID_USB_INTERFACES"),
|
|
||||||
"id_vendor": prop_str(&event, "ID_VENDOR"),
|
|
||||||
"id_model": prop_str(&event, "ID_MODEL"),
|
|
||||||
}),
|
|
||||||
timestamp: now_unix_ms(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if tx.blocking_send(msg).is_err() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn enumerate_with_udev(subsystems: &[String]) -> Result<Vec<ScannedDevice>> {
|
fn enumerate_with_udev(subsystems: &[String]) -> Result<Vec<ScannedDevice>> {
|
||||||
let mut enumerator = udev::Enumerator::new()?;
|
let mut enumerator = udev::Enumerator::new()?;
|
||||||
for subsystem in subsystems {
|
for subsystem in subsystems {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
# Maintainer: Your Name <you@example.com>
|
# Maintainer: Your Name <you@example.com>
|
||||||
|
|
||||||
pkgname=breadd
|
pkgname=bread
|
||||||
pkgver=0.1.0
|
pkgver=0.1.0
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Bread daemon - event normalizer and automation runtime"
|
pkgdesc="Bread - event normalizer and automation runtime"
|
||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
url="https://github.com/Breadway/bread"
|
url="https://github.com/Breadway/bread"
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
|
|
@ -19,7 +19,6 @@ build() {
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
cd "${srcdir}/${pkgname}-${pkgver}"
|
cd "${srcdir}/${pkgname}-${pkgver}"
|
||||||
install -Dm755 target/release/breadd "${pkgdir}/usr/bin/breadd"
|
|
||||||
install -Dm755 target/release/bread "${pkgdir}/usr/bin/bread"
|
install -Dm755 target/release/bread "${pkgdir}/usr/bin/bread"
|
||||||
install -Dm644 packaging/systemd/breadd.service "${pkgdir}/usr/lib/systemd/user/breadd.service"
|
install -Dm644 packaging/systemd/bread.service "${pkgdir}/usr/lib/systemd/user/bread.service"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue