Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/edda

crates/appliance-pid1/src/console.rs

//! **The machine's graphics console** (Gunnar's `pid1::{mirror_banner_to_gfx_console,
//! open_gfx_console}`, moved here). On the appliance `console=tty0 console=ttyS0,…` makes
//! `/dev/console` the serial line, so a KVM or cloud screen shows a kernel log that never
//! names the product (measured 2026-08-12, QMP `screendump`). [`mirror_to_gfx_console`]
//! writes the same bytes to `/dev/tty0`, appliance only: a privileged container is PID 1
//! too and can see the HOST's `/dev/tty0`, so the second gate is `korp.entry=` on the
//! kernel command line. Best effort: the initramfs `/dev` holds only `console`, so the
//! node is made here (char 4,0), and a headless machine simply has no VT.

/// **`/dev/tty0` open for writing** — the currently visible VT, made (char 4,0) when the
/// initramfs `/dev` did not ship it. `None` for a headless machine and on ANY failure.
/// NOT appliance-gated itself: a caller that forgets scribbles on a host's real console
/// from inside a privileged container (see [`mirror_to_gfx_console`]).
pub fn open_gfx_console() -> Option<std::fs::File> {
    let tty0 = std::path::Path::new("/dev/tty0");
    if !tty0.exists() {
        use rustix::fs::{makedev, mknodat, FileType, Mode, CWD};
        mknodat(CWD, tty0, FileType::CharacterDevice, Mode::from_raw_mode(0o600), makedev(4, 0)).ok()?;
    }
    std::fs::OpenOptions::new().write(true).open(tty0).ok()
}

/// **Mirror `text` to the graphics console, on the appliance only** (PID 1 AND booted
/// by korp-start, [`crate::stop::on_appliance`]). Whether it was written; every failure
/// is swallowed: a machine with no screen must not fail to serve.
pub fn mirror_to_gfx_console(text: &str) -> bool {
    if !crate::stop::on_appliance() {
        return false;
    }
    match open_gfx_console() {
        Some(mut vt) => {
            use std::io::Write as _;
            vt.write_all(text.as_bytes()).is_ok()
        }
        None => false,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Off the appliance (this test process) the mirror writes nothing, anywhere.
    #[test]
    fn off_the_appliance_the_mirror_is_a_no_op() {
        assert!(!mirror_to_gfx_console("banner\r\n"), "a test process is not the appliance: nothing written");
    }
}