fix: handover too early
This commit is contained in:
1 parent
b126596973
commit
58bef783cc
7 files changed
+57
-27
No files matched your search
@@ -178,7 +178,10 @@ NixOS, or the `vt.default_red`, `_grn` and `_blu` kernel parameters elsewhere.
|
||||
`keep-finished-units-for` is how long a finished unit stays in the tree, faded,
|
||||
before it leaves. Runs shorter than `hide-runs-shorter-than` get no timer and no
|
||||
timeline bar. `keep-final-frame-for` is how long the last frame stays before the
|
||||
console is handed back; `--hold` overrides it.
|
||||
console is handed back; `--hold` overrides it. When a display manager is
|
||||
starting, bootvine instead waits for it to switch to its own terminal, up to
|
||||
`wait-for-display-manager`, so the console's status lines never show in
|
||||
between.
|
||||
|
||||
`bootvine check /etc/bootvine.toml` reports unknown keys and bad values; at
|
||||
boot, bootvine ignores an invalid file and uses the defaults. The initrd hooks
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ in
|
||||
a live dependency tree of systemd jobs on the boot console. With a
|
||||
systemd initrd it starts there and survives the switch to the real root;
|
||||
otherwise it starts in stage 2. It hands the console back once the
|
||||
display manager starts or the default target is reached, and comes back
|
||||
display manager switches to its terminal or the default target is
|
||||
reached, and comes back
|
||||
for shutdown until systemd hands over to systemd-shutdown
|
||||
'';
|
||||
|
||||
|
||||
@@ -226,6 +226,15 @@ impl BootState {
|
||||
self.units.get(root).is_some_and(|root| !root.is_pending())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn display_manager_started(&self) -> bool {
|
||||
self.handoff_unit
|
||||
.as_deref()
|
||||
.and_then(|unit| self.units.get(unit))
|
||||
.and_then(|handoff| handoff.activity.state)
|
||||
.is_some_and(|state| state != ActiveState::Inactive)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn tally(&self) -> Tally {
|
||||
let carried = Tally {
|
||||
@@ -287,8 +296,10 @@ mod tests {
|
||||
fn display_manager_activation_does_not_hand_the_console_over() {
|
||||
let mut state = sample();
|
||||
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
||||
assert!(!state.display_manager_started());
|
||||
state.update_activity(HANDOFF_UNIT, activating(6000 * MS));
|
||||
assert!(!state.is_complete());
|
||||
assert!(state.display_manager_started());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -19,7 +19,6 @@ pub struct Console {
|
||||
quiet_kernel: Option<QuietKernelConsole>,
|
||||
foreground: Option<ForegroundVt>,
|
||||
for_system: bool,
|
||||
handing_over: bool,
|
||||
pub glyphs: Glyphs,
|
||||
pub bold_is_brightness: bool,
|
||||
}
|
||||
@@ -38,7 +37,6 @@ impl Console {
|
||||
ForegroundVt::take()
|
||||
},
|
||||
for_system,
|
||||
handing_over: false,
|
||||
glyphs: font_glyphs(),
|
||||
bold_is_brightness: own_vt().is_some(),
|
||||
}
|
||||
@@ -65,8 +63,7 @@ impl Console {
|
||||
.quiet_kernel
|
||||
.as_mut()
|
||||
.is_some_and(QuietKernelConsole::keep_quiet);
|
||||
let terminal_was_taken =
|
||||
!self.handing_over && self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
||||
let terminal_was_taken = self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
||||
let glyphs = font_glyphs();
|
||||
let font_changed = glyphs != self.glyphs;
|
||||
self.glyphs = glyphs;
|
||||
@@ -74,7 +71,7 @@ impl Console {
|
||||
}
|
||||
|
||||
pub fn begin_handover(&mut self) {
|
||||
self.handing_over = true;
|
||||
self.set_grip(TerminalGrip::Yielding);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -85,8 +82,12 @@ impl Console {
|
||||
}
|
||||
|
||||
pub fn leave_console(&mut self) {
|
||||
self.set_grip(TerminalGrip::Surrendered);
|
||||
}
|
||||
|
||||
fn set_grip(&mut self, grip: TerminalGrip) {
|
||||
if let Some(foreground) = &mut self.foreground {
|
||||
foreground.leave = true;
|
||||
foreground.grip = grip;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,10 +180,17 @@ struct VtState {
|
||||
_state: u16,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum TerminalGrip {
|
||||
Insisting,
|
||||
Yielding,
|
||||
Surrendered,
|
||||
}
|
||||
|
||||
struct ForegroundVt {
|
||||
own: u16,
|
||||
previous: u16,
|
||||
leave: bool,
|
||||
grip: TerminalGrip,
|
||||
}
|
||||
|
||||
fn active_vt() -> Option<u16> {
|
||||
@@ -210,12 +218,12 @@ impl ForegroundVt {
|
||||
Some(Self {
|
||||
own,
|
||||
previous,
|
||||
leave: false,
|
||||
grip: TerminalGrip::Insisting,
|
||||
})
|
||||
}
|
||||
|
||||
fn insist(&self) -> bool {
|
||||
active_vt().is_some_and(|active| active != self.own) && activate(self.own).is_ok()
|
||||
self.grip == TerminalGrip::Insisting && self.taken_away() && activate(self.own).is_ok()
|
||||
}
|
||||
|
||||
fn taken_away(&self) -> bool {
|
||||
@@ -229,7 +237,7 @@ impl Drop for ForegroundVt {
|
||||
eprintln!("bootvine: leaving a password prompt to the console agent on this terminal");
|
||||
return;
|
||||
}
|
||||
if self.leave {
|
||||
if self.grip == TerminalGrip::Surrendered {
|
||||
return;
|
||||
}
|
||||
let _ = activate(self.previous);
|
||||
|
||||
@@ -80,18 +80,26 @@ impl ConsoleDesk for LiveDesk {
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn begin_handover(&mut self, now: Duration, hold_for: Duration) {
|
||||
fn begin_handover(&mut self, reached: &str, deadline: Duration) {
|
||||
if self.handover_deadline.is_some() {
|
||||
return;
|
||||
}
|
||||
eprintln!("bootvine: {reached} reached, handing the console over");
|
||||
self.console.begin_handover();
|
||||
self.handover_deadline = Some(now + hold_for);
|
||||
self.handover_deadline = Some(deadline);
|
||||
}
|
||||
|
||||
fn frame_passed(&mut self, _state: &mut BootState, now: Duration) -> ControlFlow<WatchEnding> {
|
||||
let Some(deadline) = self.handover_deadline else {
|
||||
return ControlFlow::Continue(());
|
||||
};
|
||||
if self.console.console_was_taken() || now >= deadline {
|
||||
if self.console.console_was_taken() {
|
||||
eprintln!("bootvine: another program took the console, leaving it there");
|
||||
self.console.leave_console();
|
||||
ControlFlow::Break(WatchEnding::BootCompleted)
|
||||
} else if now >= deadline {
|
||||
eprintln!("bootvine: nothing took the console, switching back");
|
||||
ControlFlow::Break(WatchEnding::BootCompleted)
|
||||
} else {
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ pub trait ConsoleDesk {
|
||||
None
|
||||
}
|
||||
|
||||
fn begin_handover(&mut self, _now: Duration, _hold_for: Duration) {}
|
||||
fn begin_handover(&mut self, _reached: &str, _deadline: Duration) {}
|
||||
}
|
||||
|
||||
struct CachedProjection {
|
||||
@@ -73,7 +73,6 @@ pub struct WatchScreen<Desk> {
|
||||
pub desk: Desk,
|
||||
origin: BootOrigin,
|
||||
full_repaint_due: bool,
|
||||
handover_begun: bool,
|
||||
colors: Colors,
|
||||
timing: Timing,
|
||||
epoch: Duration,
|
||||
@@ -94,7 +93,6 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
||||
desk,
|
||||
origin,
|
||||
full_repaint_due: false,
|
||||
handover_begun: false,
|
||||
colors,
|
||||
timing,
|
||||
epoch,
|
||||
@@ -152,15 +150,13 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
||||
if !self.state.is_complete() {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
if !self.handover_begun {
|
||||
self.handover_begun = true;
|
||||
eprintln!(
|
||||
"bootvine: {} reached, handing the console over",
|
||||
self.state.root.unit().unwrap_or("boot")
|
||||
);
|
||||
self.desk
|
||||
.begin_handover(now, self.timing.keep_final_frame_for);
|
||||
}
|
||||
let hold_for = if self.state.display_manager_started() {
|
||||
self.timing.wait_for_display_manager
|
||||
} else {
|
||||
self.timing.keep_final_frame_for
|
||||
};
|
||||
self.desk
|
||||
.begin_handover(self.state.root.unit().unwrap_or("boot"), now + hold_for);
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ pub struct Timing {
|
||||
pub hide_runs_shorter_than: Duration,
|
||||
#[serde(with = "friendly_duration")]
|
||||
pub keep_final_frame_for: Duration,
|
||||
#[serde(with = "friendly_duration")]
|
||||
pub wait_for_display_manager: Duration,
|
||||
}
|
||||
|
||||
impl Default for Timing {
|
||||
@@ -31,6 +33,7 @@ impl Default for Timing {
|
||||
keep_finished_units_for: Duration::from_secs(2),
|
||||
hide_runs_shorter_than: Duration::from_secs(1),
|
||||
keep_final_frame_for: Duration::from_secs(1),
|
||||
wait_for_display_manager: Duration::from_secs(10),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user