diff --git a/native/src/base/cstr.rs b/native/src/base/cstr.rs index f2523e72d..5b7ea90ab 100644 --- a/native/src/base/cstr.rs +++ b/native/src/base/cstr.rs @@ -405,8 +405,8 @@ macro_rules! const_assert_eq { } // Assert ABI layout -const_assert_eq!(mem::size_of::<&Utf8CStr>(), mem::size_of::<[usize; 2]>()); -const_assert_eq!(mem::align_of::<&Utf8CStr>(), mem::align_of::<[usize; 2]>()); +const_assert_eq!(size_of::<&Utf8CStr>(), size_of::<[usize; 2]>()); +const_assert_eq!(align_of::<&Utf8CStr>(), align_of::<[usize; 2]>()); // File system path extensions types @@ -471,7 +471,7 @@ impl<'a> FsPathBuf<'a> { } } -impl<'a> Deref for FsPathBuf<'a> { +impl Deref for FsPathBuf<'_> { type Target = FsPath; fn deref(&self) -> &FsPath { @@ -479,7 +479,7 @@ impl<'a> Deref for FsPathBuf<'a> { } } -impl<'a> DerefMut for FsPathBuf<'a> { +impl DerefMut for FsPathBuf<'_> { fn deref_mut(&mut self) -> &mut Self::Target { FsPath::from_mut(&mut self.0) } diff --git a/native/src/base/files.rs b/native/src/base/files.rs index 335bf50b7..f5ee282a9 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -333,7 +333,7 @@ impl Directory { unsafe { let entry = &*e; let d_name = CStr::from_ptr(entry.d_name.as_ptr()); - return if d_name == cstr!(".") || d_name == cstr!("..") { + if d_name == cstr!(".") || d_name == cstr!("..") { self.read() } else { let e = DirEntry { @@ -342,7 +342,7 @@ impl Directory { d_name_len: d_name.to_bytes_with_nul().len(), }; Ok(Some(e)) - }; + } } } diff --git a/native/src/init/logging.rs b/native/src/init/logging.rs index e38d0ec6b..6a452e96e 100644 --- a/native/src/init/logging.rs +++ b/native/src/init/logging.rs @@ -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> = 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); } }