feat: support luks
This commit is contained in:
1 parent
5433f23513
commit
10eb2f7b98
4 files changed
+110
-6
No files matched your search
+53
-4
@@ -15,20 +15,58 @@ const VT_WAITACTIVE: Opcode = 0x5607;
|
||||
const VIRTUAL_TERMINAL_PREFIX: &str = "/dev/tty";
|
||||
const KERNEL_PRINTK: &str = "/proc/sys/kernel/printk";
|
||||
const ALERTS_ONLY: &str = "1";
|
||||
const PASSWORD_REQUESTS: &str = "/run/systemd/ask-password";
|
||||
const PASSWORD_REQUEST_PREFIX: &str = "ask.";
|
||||
|
||||
pub struct Console {
|
||||
quiet_kernel: Option<QuietKernelConsole>,
|
||||
foreground: Option<ForegroundVt>,
|
||||
yields_to_password_prompts: bool,
|
||||
pub glyphs: Glyphs,
|
||||
}
|
||||
|
||||
impl Console {
|
||||
pub fn take(quiets_kernel: bool) -> Self {
|
||||
pub fn take(for_system: bool) -> Self {
|
||||
let prompt_showing = for_system && password_requested();
|
||||
Self {
|
||||
quiet_kernel: quiets_kernel.then(QuietKernelConsole::take).flatten(),
|
||||
quiet_kernel: for_system.then(QuietKernelConsole::take).flatten(),
|
||||
foreground: if prompt_showing {
|
||||
None
|
||||
} else {
|
||||
ForegroundVt::take()
|
||||
},
|
||||
yields_to_password_prompts: for_system,
|
||||
glyphs: font_glyphs(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_way_for_password_prompts(&mut self) {
|
||||
if !self.yields_to_password_prompts {
|
||||
return;
|
||||
}
|
||||
if password_requested() {
|
||||
self.step_aside();
|
||||
} else {
|
||||
self.come_forward();
|
||||
}
|
||||
}
|
||||
|
||||
fn step_aside(&mut self) {
|
||||
if self.foreground.take().is_some() {
|
||||
eprintln!("bootvine: stepping aside for a password prompt");
|
||||
}
|
||||
}
|
||||
|
||||
fn come_forward(&mut self) {
|
||||
if self.foreground.is_some() {
|
||||
return;
|
||||
}
|
||||
self.foreground = ForegroundVt::take();
|
||||
if self.foreground.is_some() {
|
||||
eprintln!("bootvine: password prompt answered, taking the console back");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keep_up(&mut self) {
|
||||
if let Some(quiet_kernel) = &mut self.quiet_kernel {
|
||||
quiet_kernel.keep_quiet();
|
||||
@@ -63,6 +101,17 @@ impl QuietKernelConsole {
|
||||
}
|
||||
}
|
||||
|
||||
fn password_requested() -> bool {
|
||||
fs::read_dir(PASSWORD_REQUESTS).is_ok_and(|entries| {
|
||||
entries.flatten().any(|entry| {
|
||||
entry
|
||||
.file_name()
|
||||
.to_string_lossy()
|
||||
.starts_with(PASSWORD_REQUEST_PREFIX)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn font_glyphs() -> Glyphs {
|
||||
font_characters().map_or_else(Glyphs::default, |characters| {
|
||||
Glyphs::fitting(|symbol| symbol.is_ascii() || characters.contains(&symbol))
|
||||
@@ -123,12 +172,12 @@ struct VtState {
|
||||
_state: u16,
|
||||
}
|
||||
|
||||
pub struct ForegroundVt {
|
||||
struct ForegroundVt {
|
||||
previous: u16,
|
||||
}
|
||||
|
||||
impl ForegroundVt {
|
||||
pub fn take() -> Option<Self> {
|
||||
fn take() -> Option<Self> {
|
||||
let name = ttyname(stdin(), Vec::new()).ok()?;
|
||||
let own: u16 = name
|
||||
.to_str()
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ use signal_hook::{consts::SIGTERM, flag};
|
||||
|
||||
use crate::{
|
||||
clock::monotonic_now,
|
||||
console::{Console, ForegroundVt},
|
||||
console::Console,
|
||||
error::Error,
|
||||
feed::Feed,
|
||||
sysroot::INITRD_RELEASE,
|
||||
@@ -63,7 +63,6 @@ pub fn run(options: &Options) -> Result<(), Error> {
|
||||
let mut state = BootState::new(phase);
|
||||
let mut feed = Feed::new(options.scope, options.target.clone());
|
||||
let mut console = Console::take(options.scope == Scope::System);
|
||||
let _foreground = ForegroundVt::take();
|
||||
let mut terminal = ratatui::try_init()?;
|
||||
let watched = watch(
|
||||
&mut state,
|
||||
@@ -119,6 +118,7 @@ fn watch(
|
||||
let mut last_full_repaint = Instant::now();
|
||||
loop {
|
||||
feed.pump(state, FRAME_INTERVAL)?;
|
||||
console.make_way_for_password_prompts();
|
||||
let repaint_due = feed.connections != painted_connections
|
||||
|| last_full_repaint.elapsed() >= FULL_REPAINT_INTERVAL;
|
||||
if repaint_due {
|
||||
|
||||
Reference in new issue
Block a user