Skip to content

Commit

Permalink
muvm-guest: Reopen the system tty (hvc0)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
asahilina committed Oct 15, 2024
1 parent 475d018 commit eed5710
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/muvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [] }
Expand Down
12 changes: 12 additions & 0 deletions crates/muvm/src/guest/bin/muvm-guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -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();
Expand Down

0 comments on commit eed5710

Please sign in to comment.