Skip to content

Commit

Permalink
ksud: catch dmesg in bootlog
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Mar 11, 2024
1 parent fe7ec37 commit d77988c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions userspace/ksud/src/init_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ pub fn on_post_data_fs() -> Result<()> {
utils::umask(0);

#[cfg(unix)]
let _ = catch_bootlog();
let _ = catch_bootlog("logcat", vec!["logcat"]);
#[cfg(unix)]
let _ = catch_bootlog("dmesg", vec!["dmesg", "-w"]);

if utils::has_magisk() {
warn!("Magisk detected, skip post-fs-data!");
Expand Down Expand Up @@ -265,21 +267,23 @@ pub fn on_boot_completed() -> Result<()> {
}

#[cfg(unix)]
fn catch_bootlog() -> Result<()> {
fn catch_bootlog(logname: &str, command: Vec<&str>) -> Result<()> {
use std::os::unix::process::CommandExt;
use std::process::Stdio;

let logdir = Path::new(defs::LOG_DIR);
utils::ensure_dir_exists(logdir)?;
let bootlog = logdir.join("boot.log");
let oldbootlog = logdir.join("boot.old.log");
let bootlog = logdir.join(format!("{logname}.log"));
let oldbootlog = logdir.join(format!("{logname}.old.log"));

if bootlog.exists() {
std::fs::rename(&bootlog, oldbootlog)?;
}

let bootlog = std::fs::File::create(bootlog)?;

let mut args = vec!["-s", "9", "30s"];
args.extend_from_slice(&command);
// timeout -s 9 30s logcat > boot.log
let result = unsafe {
std::process::Command::new("timeout")
Expand All @@ -288,10 +292,7 @@ fn catch_bootlog() -> Result<()> {
utils::switch_cgroups();
Ok(())
})
.arg("-s")
.arg("9")
.arg("30s")
.arg("logcat")
.args(args)
.stdout(Stdio::from(bootlog))
.spawn()
};
Expand Down

0 comments on commit d77988c

Please sign in to comment.