Skip to content

Commit 3614978

Browse files
WhatAmISupposedToPutHereslp
authored andcommitted
Add support for input device passthrough
Signed-off-by: Sasha Finkelstein <[email protected]>
1 parent d6e7e17 commit 3614978

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

crates/krun-guest/src/bin/krun-guest.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use krun_guest::user::setup_user;
1313
use krun_guest::x11::setup_x11_forwarding;
1414
use log::debug;
1515
use rustix::process::{getrlimit, setrlimit, Resource};
16+
use utils::env::find_in_path;
1617

1718
fn main() -> Result<()> {
1819
env_logger::init();
@@ -37,11 +38,16 @@ fn main() -> Result<()> {
3738
if let Err(err) = mount_filesystems() {
3839
return Err(err).context("Failed to mount filesystems, bailing out");
3940
}
41+
Command::new("/usr/lib/systemd/systemd-udevd").spawn()?;
4042

4143
setup_fex()?;
4244

4345
configure_network()?;
4446

47+
if let Some(hidpipe_client_path) = find_in_path("hidpipe-client")? {
48+
Command::new(hidpipe_client_path).arg(format!("{}", options.uid)).spawn()?;
49+
}
50+
4551
let run_path = match setup_user(options.username, options.uid, options.gid) {
4652
Ok(p) => p,
4753
Err(err) => return Err(err).context("Failed to set up user, bailing out"),

crates/krun/src/bin/krun.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ fn main() -> Result<()> {
179179
return Err(err).context("Failed to configure vsock for pulse socket");
180180
}
181181
}
182+
let hidpipe_path = Path::new(&run_path).join("hidpipe");
183+
if hidpipe_path.exists() {
184+
let hidpipe_path = CString::new(
185+
hidpipe_path
186+
.to_str()
187+
.expect("hidpipe_path should not contain invalid UTF-8"),
188+
)
189+
.context("Failed to process `hidpipe` path as it contains NUL character")?;
190+
// SAFETY: `hidpipe_path` is a pointer to a `CString` with long enough lifetime.
191+
let err = unsafe { krun_add_vsock_port(ctx_id, 3334, hidpipe_path.as_ptr()) };
192+
if err < 0 {
193+
let err = Errno::from_raw_os_error(-err);
194+
return Err(err).context("Failed to configure vsock for hidpipe socket");
195+
}
196+
}
182197
}
183198

184199
// Forward the native X11 display into the guest as a socket

0 commit comments

Comments
 (0)