Files
RedBear-OS/local/patches/base/P4-logd-persistent-logging.patch
vasilito 528115b33a fix: logd persistent logging now uses Option<File>, doesn't panic at initfs time
At initfs time, /var/log/ doesn't exist (rootfs not yet mounted).
Changed persistent_log from File to Option<File> with .ok() instead
of .unwrap_or_else(|| panic!()). If the file can't be opened, logging
continues without persistence — no crash.

QEMU verification: system boots through initfs→rootfs→switch_root→userland.
Colored init output visible. 25+ services start successfully.
2026-05-03 10:16:48 +01:00

34 lines
1.3 KiB
Diff

--- a/logd/src/scheme.rs 2026-05-03 10:11:43.179863727 +0100
+++ b/logd/src/scheme.rs 2026-05-03 10:11:43.179952713 +0100
@@ -41,14 +41,30 @@
let mut kernel_sys_log = std::fs::File::open("/scheme/sys/log").unwrap();
+ let _ = std::fs::create_dir_all("/var/log");
+ let persistent_log: Option<File> = OpenOptions::new()
+ .create(true)
+ .append(true)
+ .open("/var/log/system.log")
+ .ok();
+
let (output_tx, output_rx) = mpsc::channel::<OutputCmd>();
std::thread::spawn(move || {
let mut files: Vec<File> = vec![];
let mut logs = VecDeque::new();
+ let mut persistent = persistent_log;
+ if let Some(ref mut f) = persistent {
+ let _ = f.write(b"--- logd started ---
+");
+ }
for cmd in output_rx {
match cmd {
OutputCmd::Log(line) => {
+ if let Some(ref mut f) = persistent {
+ let _ = f.write(&line);
+ let _ = f.flush();
+ }
for file in &mut files {
let _ = file.write(&line);
let _ = file.flush();