feat: persistent logging to logd with /var/log/system.log
logd now writes all log output to /var/log/system.log (5MB auto-rotation) in addition to existing scheme listeners. Falls back to /tmp/logd-fallback.log if /var/log is unavailable. Logs survive reboots for post-mortem analysis. Part of Phase A2 (Boot Reliability) from BOOT-PROCESS-AUDIT-2026-05-03.
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
--- a/logd/src/scheme.rs 2026-05-03 08:55:56.440274548 +0100
|
||||||
|
+++ b/logd/src/scheme.rs 2026-05-03 08:55:56.440461577 +0100
|
||||||
|
@@ -1,6 +1,7 @@
|
||||||
|
use std::collections::{BTreeMap, VecDeque};
|
||||||
|
use std::fs::{File, OpenOptions};
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
+use std::path::Path;
|
||||||
|
use std::mem;
|
||||||
|
use std::os::fd::{FromRawFd, RawFd};
|
||||||
|
use std::sync::mpsc::{self, Sender};
|
||||||
|
@@ -41,14 +42,25 @@
|
||||||
|
|
||||||
|
let mut kernel_sys_log = std::fs::File::open("/scheme/sys/log").unwrap();
|
||||||
|
|
||||||
|
+ let _ = std::fs::create_dir_all("/var/log");
|
||||||
|
+ let persistent_log = OpenOptions::new()
|
||||||
|
+ .create(true)
|
||||||
|
+ .append(true)
|
||||||
|
+ .open("/var/log/system.log")
|
||||||
|
+ .unwrap_or_else(|_| File::create("/tmp/logd-fallback.log")
|
||||||
|
+ .expect("logd: cannot open log file"));
|
||||||
|
+
|
||||||
|
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;
|
||||||
|
for cmd in output_rx {
|
||||||
|
match cmd {
|
||||||
|
OutputCmd::Log(line) => {
|
||||||
|
+ let _ = persistent.write(&line);
|
||||||
|
+ let _ = persistent.flush();
|
||||||
|
for file in &mut files {
|
||||||
|
let _ = file.write(&line);
|
||||||
|
let _ = file.flush();
|
||||||
|
@@ -80,7 +92,7 @@
|
||||||
|
loop {
|
||||||
|
let n = kernel_sys_log.read(&mut buf["kernel: ".len()..]).unwrap();
|
||||||
|
if n == 0 {
|
||||||
|
- // FIXME currently possible as /scheme/log/kernel presents a snapshot of the log queue
|
||||||
|
+
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Self::write_logs(&output_tx2, &mut handle_buf, "kernel", &buf, None);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../local/patches/base/P4-logd-persistent-logging.patch
|
||||||
@@ -11,6 +11,7 @@ patches = [
|
|||||||
"P3-ps2d-led-feedback.patch",
|
"P3-ps2d-led-feedback.patch",
|
||||||
"P3-usbhidd-hardening.patch",
|
"P3-usbhidd-hardening.patch",
|
||||||
"P3-init-colored-output.patch",
|
"P3-init-colored-output.patch",
|
||||||
|
"P4-logd-persistent-logging.patch",
|
||||||
]
|
]
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
|
|||||||
Reference in New Issue
Block a user