Skip to content

Commit eed5710

Browse files
committed
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 <[email protected]>
1 parent 475d018 commit eed5710

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

crates/muvm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env_logger = { version = "0.11.3", default-features = false, features = ["auto-c
1616
krun-sys = { path = "../krun-sys", version = "1.9.1", default-features = false, features = [] }
1717
log = { version = "0.4.21", default-features = false, features = ["kv"] }
1818
nix = { version = "0.28.0", default-features = false, features = ["user"] }
19-
rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "system", "use-libc-auxv"] }
19+
rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "stdio", "system", "use-libc-auxv"] }
2020
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
2121
serde_json = { version = "1.0.117", default-features = false, features = ["std"] }
2222
tempfile = { version = "3.10.1", default-features = false, features = [] }

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use muvm::guest::user::setup_user;
1515
use muvm::guest::x11::setup_x11_forwarding;
1616
use muvm::utils::env::find_in_path;
1717
use nix::unistd::User;
18+
use rustix::fd::AsFd;
1819
use rustix::process::{getrlimit, setrlimit, Resource};
1920

2021
fn main() -> Result<()> {
@@ -40,6 +41,17 @@ fn main() -> Result<()> {
4041
if let Err(err) = mount_filesystems() {
4142
return Err(err).context("Failed to mount filesystems, bailing out");
4243
}
44+
45+
// Use the correct TTY, which fixes pty issues etc. (/dev/console cannot be a controlling tty)
46+
let console = std::fs::OpenOptions::new()
47+
.read(true)
48+
.write(true)
49+
.create(false)
50+
.open("/dev/hvc0")?;
51+
rustix::stdio::dup2_stdin(console.as_fd())?;
52+
rustix::stdio::dup2_stdout(console.as_fd())?;
53+
rustix::stdio::dup2_stderr(console.as_fd())?;
54+
4355
Command::new("/usr/lib/systemd/systemd-udevd").spawn()?;
4456

4557
let user = User::from_uid(options.uid)?.unwrap();

0 commit comments

Comments
 (0)