Address clippy warnings

This commit is contained in:
topjohnwu
2024-12-09 18:26:39 -08:00
committed by John Wu
parent 9e26b73813
commit 2654382c43
3 changed files with 16 additions and 13 deletions
+10 -7
View File
@@ -1,15 +1,15 @@
use std::cell::UnsafeCell;
use std::fs::File;
use std::io::{IoSlice, Write};
use base::libc::{
makedev, mknod, syscall, SYS_dup3, O_CLOEXEC, O_RDWR, O_WRONLY, STDERR_FILENO, STDIN_FILENO,
STDOUT_FILENO, S_IFCHR,
};
use base::{cstr, exit_on_error, open_fd, raw_cstr, FsPath, LogLevel, Logger, Utf8CStr, LOGGER};
use std::fs::File;
use std::io::{IoSlice, Write};
use std::mem;
use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
// SAFETY: magiskinit is single threaded
static mut KMSG: UnsafeCell<Option<File>> = UnsafeCell::new(None);
static mut KMSG: RawFd = -1;
pub fn setup_klog() {
unsafe {
@@ -33,7 +33,7 @@ pub fn setup_klog() {
fd = open_fd!(cstr!("/kmsg"), O_WRONLY | O_CLOEXEC);
FsPath::from(cstr!("/kmsg")).remove().ok();
}
*KMSG.get() = fd.map(|fd| fd.into()).ok();
KMSG = fd.map(|fd| fd.into_raw_fd()).unwrap_or(-1);
}
// Disable kmsg rate limiting
@@ -46,10 +46,13 @@ pub fn setup_klog() {
}
fn kmsg_log_write(_: LogLevel, msg: &Utf8CStr) {
if let Some(kmsg) = unsafe { &mut *KMSG.get() } {
let fd = unsafe { KMSG };
if fd >= 0 {
let io1 = IoSlice::new("magiskinit: ".as_bytes());
let io2 = IoSlice::new(msg.as_bytes());
let mut kmsg = unsafe { File::from_raw_fd(fd) };
let _ = kmsg.write_vectored(&[io1, io2]).ok();
mem::forget(kmsg);
}
}