From eed5710d74ebfe72067cecec7726996ceef65d6b Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Wed, 16 Oct 2024 01:14:16 +0900 Subject: [PATCH] muvm-guest: Reopen the system tty (hvc0) This fixes the classic: -bash: cannot set terminal process group (-1): Inappropriate ioctl for device -bash: no job control in this shell I'm not entirely sure why this doesn't happen with our main shell, but it happens with things like sudo. (There are a bunch of other things needed to make sudo work, of course) Signed-off-by: Asahi Lina --- crates/muvm/Cargo.toml | 2 +- crates/muvm/src/guest/bin/muvm-guest.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/muvm/Cargo.toml b/crates/muvm/Cargo.toml index 4451d51..8482e09 100644 --- a/crates/muvm/Cargo.toml +++ b/crates/muvm/Cargo.toml @@ -16,7 +16,7 @@ env_logger = { version = "0.11.3", default-features = false, features = ["auto-c krun-sys = { path = "../krun-sys", version = "1.9.1", default-features = false, features = [] } log = { version = "0.4.21", default-features = false, features = ["kv"] } nix = { version = "0.28.0", default-features = false, features = ["user"] } -rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "system", "use-libc-auxv"] } +rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "stdio", "system", "use-libc-auxv"] } serde = { version = "1.0.203", default-features = false, features = ["derive"] } serde_json = { version = "1.0.117", default-features = false, features = ["std"] } tempfile = { version = "3.10.1", default-features = false, features = [] } diff --git a/crates/muvm/src/guest/bin/muvm-guest.rs b/crates/muvm/src/guest/bin/muvm-guest.rs index 4a8d5d0..ee50433 100644 --- a/crates/muvm/src/guest/bin/muvm-guest.rs +++ b/crates/muvm/src/guest/bin/muvm-guest.rs @@ -15,6 +15,7 @@ use muvm::guest::user::setup_user; use muvm::guest::x11::setup_x11_forwarding; use muvm::utils::env::find_in_path; use nix::unistd::User; +use rustix::fd::AsFd; use rustix::process::{getrlimit, setrlimit, Resource}; fn main() -> Result<()> { @@ -40,6 +41,17 @@ fn main() -> Result<()> { if let Err(err) = mount_filesystems() { return Err(err).context("Failed to mount filesystems, bailing out"); } + + // Use the correct TTY, which fixes pty issues etc. (/dev/console cannot be a controlling tty) + let console = std::fs::OpenOptions::new() + .read(true) + .write(true) + .create(false) + .open("/dev/hvc0")?; + rustix::stdio::dup2_stdin(console.as_fd())?; + rustix::stdio::dup2_stdout(console.as_fd())?; + rustix::stdio::dup2_stderr(console.as_fd())?; + Command::new("/usr/lib/systemd/systemd-udevd").spawn()?; let user = User::from_uid(options.uid)?.unwrap();