mirror of
https://github.com/joleuger/vuinputd.git
synced 2026-07-18 00:45:07 +00:00
Make udev_event (aka netlink message) container engine aware
This commit is contained in:
parent
218fbdbcbf
commit
e6c38be172
2 changed files with 62 additions and 21 deletions
|
|
@ -2,6 +2,8 @@
|
|||
//
|
||||
// Author: Johannes Leupolz <dev@leupolz.eu>
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::bail;
|
||||
use async_trait::async_trait;
|
||||
|
||||
|
|
@ -45,11 +47,6 @@ pub trait InjectionStrategy {
|
|||
minor: u64,
|
||||
) -> anyhow::Result<()>;
|
||||
|
||||
/// Emit netlink message.
|
||||
/// emit_netlink_message is the same for all container engines, we add
|
||||
/// a method to enable more flexibility in the future and also allow tests.
|
||||
// async fn emit_netlink_message(&self, netlink_message: HashMap<String, String>,) -> anyhow::Result<()>;
|
||||
|
||||
/// Remove runtime data.
|
||||
async fn remove_udev_runtime_data(
|
||||
&self,
|
||||
|
|
@ -57,6 +54,13 @@ pub trait InjectionStrategy {
|
|||
major: u64,
|
||||
minor: u64,
|
||||
) -> anyhow::Result<()>;
|
||||
|
||||
/// Emit netlink message.
|
||||
async fn emit_netlink_message(
|
||||
&self,
|
||||
requesting_process: &RequestingProcess,
|
||||
netlink_message: HashMap<String, String>,
|
||||
) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
pub struct GenericPlacementInContainer {}
|
||||
|
|
@ -149,6 +153,23 @@ impl InjectionStrategy for GenericPlacementInContainer {
|
|||
let _exit_info = process_tools::await_process(Pid::Pid(child_pid_2)).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Emit netlink message.
|
||||
async fn emit_netlink_message(
|
||||
&self,
|
||||
requesting_process: &RequestingProcess,
|
||||
netlink_message: HashMap<String, String>,
|
||||
) -> anyhow::Result<()> {
|
||||
let emit_netlink_message = Action::EmitNetlinkMessage {
|
||||
netlink_message: netlink_message,
|
||||
};
|
||||
|
||||
let child_pid = process_tools::start_action(emit_netlink_message, requesting_process)
|
||||
.expect("subprocess should work");
|
||||
|
||||
let _exit_info = process_tools::await_process(Pid::Pid(child_pid)).await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -213,6 +234,18 @@ impl InjectionStrategy for GenericPlacementOnHost {
|
|||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
/// Emit netlink message.
|
||||
async fn emit_netlink_message(
|
||||
&self,
|
||||
requesting_process: &RequestingProcess,
|
||||
netlink_message: HashMap<String, String>,
|
||||
) -> anyhow::Result<()> {
|
||||
PLACEMENT_IN_CONTAINER
|
||||
.emit_netlink_message(requesting_process, netlink_message)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -255,6 +288,17 @@ impl InjectionStrategy for GenericSendNetlinkMessageOnly {
|
|||
) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Emit netlink message.
|
||||
async fn emit_netlink_message(
|
||||
&self,
|
||||
requesting_process: &RequestingProcess,
|
||||
netlink_message: HashMap<String, String>,
|
||||
) -> anyhow::Result<()> {
|
||||
PLACEMENT_IN_CONTAINER
|
||||
.emit_netlink_message(requesting_process, netlink_message)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -306,13 +350,7 @@ impl InjectionStrategy for Incus {
|
|||
global_config::Scope::Single(container_name) => container_name,
|
||||
};
|
||||
let child = std::process::Command::new("/usr/bin/incus")
|
||||
.args([
|
||||
"config",
|
||||
"device",
|
||||
"remove",
|
||||
container_name,
|
||||
devname,
|
||||
])
|
||||
.args(["config", "device", "remove", container_name, devname])
|
||||
.spawn()?;
|
||||
let output = child.wait_with_output()?;
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
|
|
@ -343,4 +381,15 @@ impl InjectionStrategy for Incus {
|
|||
.remove_udev_runtime_data(requesting_process, major, minor)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Emit netlink message.
|
||||
async fn emit_netlink_message(
|
||||
&self,
|
||||
requesting_process: &RequestingProcess,
|
||||
netlink_message: HashMap<String, String>,
|
||||
) -> anyhow::Result<()> {
|
||||
PLACEMENT_IN_CONTAINER
|
||||
.emit_netlink_message(requesting_process, netlink_message)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,15 +158,7 @@ impl EmitUdevEventJob {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
// this is always in the container
|
||||
let emit_netlink_message = Action::EmitNetlinkMessage {
|
||||
netlink_message: netlink_data.clone(),
|
||||
};
|
||||
|
||||
let child_pid = process_tools::start_action(emit_netlink_message, &self.requesting_process)
|
||||
.expect("subprocess should work");
|
||||
|
||||
let _exit_info = await_process(Pid::Pid(child_pid)).await.unwrap();
|
||||
injector.emit_netlink_message(&self.requesting_process, netlink_data).await.unwrap();
|
||||
|
||||
self.set_state(&State::Finished);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue