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,
|
`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
|
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
|
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
|
`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
|
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
|
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;
|
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
|
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
|
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())
|
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]
|
#[must_use]
|
||||||
pub fn tally(&self) -> Tally {
|
pub fn tally(&self) -> Tally {
|
||||||
let carried = Tally {
|
let carried = Tally {
|
||||||
@@ -287,8 +296,10 @@ mod tests {
|
|||||||
fn display_manager_activation_does_not_hand_the_console_over() {
|
fn display_manager_activation_does_not_hand_the_console_over() {
|
||||||
let mut state = sample();
|
let mut state = sample();
|
||||||
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
||||||
|
assert!(!state.display_manager_started());
|
||||||
state.update_activity(HANDOFF_UNIT, activating(6000 * MS));
|
state.update_activity(HANDOFF_UNIT, activating(6000 * MS));
|
||||||
assert!(!state.is_complete());
|
assert!(!state.is_complete());
|
||||||
|
assert!(state.display_manager_started());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ pub struct Console {
|
|||||||
quiet_kernel: Option<QuietKernelConsole>,
|
quiet_kernel: Option<QuietKernelConsole>,
|
||||||
foreground: Option<ForegroundVt>,
|
foreground: Option<ForegroundVt>,
|
||||||
for_system: bool,
|
for_system: bool,
|
||||||
handing_over: bool,
|
|
||||||
pub glyphs: Glyphs,
|
pub glyphs: Glyphs,
|
||||||
pub bold_is_brightness: bool,
|
pub bold_is_brightness: bool,
|
||||||
}
|
}
|
||||||
@@ -38,7 +37,6 @@ impl Console {
|
|||||||
ForegroundVt::take()
|
ForegroundVt::take()
|
||||||
},
|
},
|
||||||
for_system,
|
for_system,
|
||||||
handing_over: false,
|
|
||||||
glyphs: font_glyphs(),
|
glyphs: font_glyphs(),
|
||||||
bold_is_brightness: own_vt().is_some(),
|
bold_is_brightness: own_vt().is_some(),
|
||||||
}
|
}
|
||||||
@@ -65,8 +63,7 @@ impl Console {
|
|||||||
.quiet_kernel
|
.quiet_kernel
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.is_some_and(QuietKernelConsole::keep_quiet);
|
.is_some_and(QuietKernelConsole::keep_quiet);
|
||||||
let terminal_was_taken =
|
let terminal_was_taken = self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
||||||
!self.handing_over && self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
|
||||||
let glyphs = font_glyphs();
|
let glyphs = font_glyphs();
|
||||||
let font_changed = glyphs != self.glyphs;
|
let font_changed = glyphs != self.glyphs;
|
||||||
self.glyphs = glyphs;
|
self.glyphs = glyphs;
|
||||||
@@ -74,7 +71,7 @@ impl Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn begin_handover(&mut self) {
|
pub fn begin_handover(&mut self) {
|
||||||
self.handing_over = true;
|
self.set_grip(TerminalGrip::Yielding);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@@ -85,8 +82,12 @@ impl Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn leave_console(&mut self) {
|
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 {
|
if let Some(foreground) = &mut self.foreground {
|
||||||
foreground.leave = true;
|
foreground.grip = grip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,10 +180,17 @@ struct VtState {
|
|||||||
_state: u16,
|
_state: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
enum TerminalGrip {
|
||||||
|
Insisting,
|
||||||
|
Yielding,
|
||||||
|
Surrendered,
|
||||||
|
}
|
||||||
|
|
||||||
struct ForegroundVt {
|
struct ForegroundVt {
|
||||||
own: u16,
|
own: u16,
|
||||||
previous: u16,
|
previous: u16,
|
||||||
leave: bool,
|
grip: TerminalGrip,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn active_vt() -> Option<u16> {
|
fn active_vt() -> Option<u16> {
|
||||||
@@ -210,12 +218,12 @@ impl ForegroundVt {
|
|||||||
Some(Self {
|
Some(Self {
|
||||||
own,
|
own,
|
||||||
previous,
|
previous,
|
||||||
leave: false,
|
grip: TerminalGrip::Insisting,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insist(&self) -> bool {
|
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 {
|
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");
|
eprintln!("bootvine: leaving a password prompt to the console agent on this terminal");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.leave {
|
if self.grip == TerminalGrip::Surrendered {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let _ = activate(self.previous);
|
let _ = activate(self.previous);
|
||||||
|
|||||||
@@ -80,18 +80,26 @@ impl ConsoleDesk for LiveDesk {
|
|||||||
ControlFlow::Continue(())
|
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.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> {
|
fn frame_passed(&mut self, _state: &mut BootState, now: Duration) -> ControlFlow<WatchEnding> {
|
||||||
let Some(deadline) = self.handover_deadline else {
|
let Some(deadline) = self.handover_deadline else {
|
||||||
return ControlFlow::Continue(());
|
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();
|
self.console.leave_console();
|
||||||
ControlFlow::Break(WatchEnding::BootCompleted)
|
ControlFlow::Break(WatchEnding::BootCompleted)
|
||||||
|
} else if now >= deadline {
|
||||||
|
eprintln!("bootvine: nothing took the console, switching back");
|
||||||
|
ControlFlow::Break(WatchEnding::BootCompleted)
|
||||||
} else {
|
} else {
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ pub trait ConsoleDesk {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn begin_handover(&mut self, _now: Duration, _hold_for: Duration) {}
|
fn begin_handover(&mut self, _reached: &str, _deadline: Duration) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CachedProjection {
|
struct CachedProjection {
|
||||||
@@ -73,7 +73,6 @@ pub struct WatchScreen<Desk> {
|
|||||||
pub desk: Desk,
|
pub desk: Desk,
|
||||||
origin: BootOrigin,
|
origin: BootOrigin,
|
||||||
full_repaint_due: bool,
|
full_repaint_due: bool,
|
||||||
handover_begun: bool,
|
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
timing: Timing,
|
timing: Timing,
|
||||||
epoch: Duration,
|
epoch: Duration,
|
||||||
@@ -94,7 +93,6 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
|||||||
desk,
|
desk,
|
||||||
origin,
|
origin,
|
||||||
full_repaint_due: false,
|
full_repaint_due: false,
|
||||||
handover_begun: false,
|
|
||||||
colors,
|
colors,
|
||||||
timing,
|
timing,
|
||||||
epoch,
|
epoch,
|
||||||
@@ -152,15 +150,13 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
|||||||
if !self.state.is_complete() {
|
if !self.state.is_complete() {
|
||||||
return ControlFlow::Continue(());
|
return ControlFlow::Continue(());
|
||||||
}
|
}
|
||||||
if !self.handover_begun {
|
let hold_for = if self.state.display_manager_started() {
|
||||||
self.handover_begun = true;
|
self.timing.wait_for_display_manager
|
||||||
eprintln!(
|
} else {
|
||||||
"bootvine: {} reached, handing the console over",
|
self.timing.keep_final_frame_for
|
||||||
self.state.root.unit().unwrap_or("boot")
|
};
|
||||||
);
|
self.desk
|
||||||
self.desk
|
.begin_handover(self.state.root.unit().unwrap_or("boot"), now + hold_for);
|
||||||
.begin_handover(now, self.timing.keep_final_frame_for);
|
|
||||||
}
|
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ pub struct Timing {
|
|||||||
pub hide_runs_shorter_than: Duration,
|
pub hide_runs_shorter_than: Duration,
|
||||||
#[serde(with = "friendly_duration")]
|
#[serde(with = "friendly_duration")]
|
||||||
pub keep_final_frame_for: Duration,
|
pub keep_final_frame_for: Duration,
|
||||||
|
#[serde(with = "friendly_duration")]
|
||||||
|
pub wait_for_display_manager: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Timing {
|
impl Default for Timing {
|
||||||
@@ -31,6 +33,7 @@ impl Default for Timing {
|
|||||||
keep_finished_units_for: Duration::from_secs(2),
|
keep_finished_units_for: Duration::from_secs(2),
|
||||||
hide_runs_shorter_than: Duration::from_secs(1),
|
hide_runs_shorter_than: Duration::from_secs(1),
|
||||||
keep_final_frame_for: 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