From 74af283d57349b5a1ef2ffc8d2fc799c10399d6a Mon Sep 17 00:00:00 2001 From: Willem Vanhulle Date: Sun, 11 Oct 2026 16:21:21 +0200 Subject: [PATCH] fix: stand down when started after boot finished --- demo/test.nix | 7 +++++++ src/run.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/demo/test.nix b/demo/test.nix index 78ddfde..4340d85 100644 --- a/demo/test.nix +++ b/demo/test.nix @@ -44,5 +44,12 @@ show_status = machine.succeed("systemctl show -p ShowStatus --value").strip() assert show_status == "yes", f"systemd status output was not restored: {show_status}" machine.screenshot("handed-over") + + foreground = machine.succeed("cat /sys/class/tty/tty0/active").strip() + machine.succeed("systemctl restart bootvine") + machine.wait_until_succeeds("systemctl show -p ActiveState --value bootvine | grep -qx inactive", timeout=10) + assert "boot already finished" in machine.succeed("journalctl -u bootvine -o cat"), "a restart after boot did not stand down" + still_foreground = machine.succeed("cat /sys/class/tty/tty0/active").strip() + assert still_foreground == foreground, f"a restart after boot took the console: {foreground} -> {still_foreground}" ''; } diff --git a/src/run.rs b/src/run.rs index 6afcc1c..5fc8041 100644 --- a/src/run.rs +++ b/src/run.rs @@ -27,7 +27,7 @@ use crate::{ error::Error, feed::Feed, sysroot::INITRD_RELEASE, - systemd::Scope, + systemd::{Scope, Session}, }; const FRAME_INTERVAL: Duration = Duration::from_millis(100); @@ -43,6 +43,14 @@ pub struct Options { pub fn run(options: &Options) -> Result<(), Error> { let terminate = Arc::new(AtomicBool::new(false)); flag::register(SIGTERM, Arc::clone(&terminate))?; + if options.scope == Scope::System + && Session::open(Scope::System) + .and_then(|session| session.boot_in_progress()) + .is_ok_and(|booting| !booting) + { + eprintln!("bootvine: boot already finished, leaving the console alone"); + return Ok(()); + } let phase = match options.scope { Scope::User => Phase::User, Scope::System if Path::new(INITRD_RELEASE).exists() => Phase::Initrd,