boot-tree: portable unit, dracut and mkinitcpio hooks, self-quieting console, minimal NixOS module
This commit is contained in:
1 parent
2b1447965a
commit
1482d4437a
13 files changed
+208
-121
No files matched your search
@@ -1,3 +1,5 @@
|
||||
use std::fs;
|
||||
|
||||
use rustix::{
|
||||
io::Errno,
|
||||
ioctl::{Getter, IntegerSetter, Opcode, ioctl},
|
||||
@@ -9,6 +11,27 @@ const VT_GETSTATE: Opcode = 0x5603;
|
||||
const VT_ACTIVATE: Opcode = 0x5606;
|
||||
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";
|
||||
|
||||
pub struct QuietKernelConsole {
|
||||
previous_level: String,
|
||||
}
|
||||
|
||||
impl QuietKernelConsole {
|
||||
pub fn take() -> Option<Self> {
|
||||
let levels = fs::read_to_string(KERNEL_PRINTK).ok()?;
|
||||
let previous_level = levels.split_whitespace().next()?.to_owned();
|
||||
fs::write(KERNEL_PRINTK, ALERTS_ONLY).ok()?;
|
||||
Some(Self { previous_level })
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for QuietKernelConsole {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::write(KERNEL_PRINTK, &self.previous_level);
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct VtState {
|
||||
|
||||
+15
@@ -18,6 +18,8 @@ use crate::{
|
||||
|
||||
const RECONNECT_PATIENCE: Duration = Duration::from_secs(60);
|
||||
const SWITCH_ROOT_UNIT: &str = "initrd-switch-root.service";
|
||||
const SILENT_STATUS: &str = "no";
|
||||
const CONFIGURED_STATUS: &str = "";
|
||||
|
||||
pub struct Feed {
|
||||
scope: Scope,
|
||||
@@ -91,6 +93,9 @@ impl Feed {
|
||||
fn connect(&mut self, state: &mut BootState) -> Result<Session, Error> {
|
||||
let session = Session::open(self.scope)?;
|
||||
session.subscribe()?;
|
||||
if self.scope == Scope::System {
|
||||
session.set_show_status(SILENT_STATUS).ok();
|
||||
}
|
||||
let requested_root = match &self.target {
|
||||
Some(target) => target.clone(),
|
||||
None => session.default_target()?,
|
||||
@@ -176,3 +181,13 @@ impl Feed {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Feed {
|
||||
fn drop(&mut self) {
|
||||
if let Some(session) = &self.session
|
||||
&& self.scope == Scope::System
|
||||
{
|
||||
session.set_show_status(CONFIGURED_STATUS).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -21,7 +21,11 @@ use rustix::system::uname;
|
||||
use signal_hook::{consts::SIGTERM, flag};
|
||||
|
||||
use crate::{
|
||||
clock::monotonic_now, console::ForegroundVt, error::Error, feed::Feed, sysroot::INITRD_RELEASE,
|
||||
clock::monotonic_now,
|
||||
console::{ForegroundVt, QuietKernelConsole},
|
||||
error::Error,
|
||||
feed::Feed,
|
||||
sysroot::INITRD_RELEASE,
|
||||
systemd::Scope,
|
||||
};
|
||||
|
||||
@@ -44,6 +48,9 @@ pub fn run(options: Options) -> Result<(), Error> {
|
||||
};
|
||||
let mut state = BootState::new(phase);
|
||||
let mut feed = Feed::new(options.scope, options.target);
|
||||
let _quiet_kernel = (options.scope == Scope::System)
|
||||
.then(QuietKernelConsole::take)
|
||||
.flatten();
|
||||
let _foreground = ForegroundVt::take();
|
||||
let mut terminal = ratatui::try_init()?;
|
||||
let watched = watch(
|
||||
|
||||
@@ -129,6 +129,17 @@ impl Session {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_show_status(&self, mode: &str) -> Result<(), Error> {
|
||||
self.call(
|
||||
DESTINATION,
|
||||
MANAGER_PATH,
|
||||
MANAGER_INTERFACE,
|
||||
"SetShowStatus",
|
||||
(mode,),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn default_target(&self) -> Result<String, Error> {
|
||||
let reply = self.call(
|
||||
DESTINATION,
|
||||
|
||||
Reference in new issue
Block a user