From e6af5ed4601eb3e614b7ebb3e177ffcc02c99e41 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 26 Apr 2024 16:28:46 -0700 Subject: [PATCH] Address Rust warnings --- native/src/init/logging.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/native/src/init/logging.rs b/native/src/init/logging.rs index e38b915b0..e38d0ec6b 100644 --- a/native/src/init/logging.rs +++ b/native/src/init/logging.rs @@ -1,3 +1,4 @@ +use std::cell::UnsafeCell; use std::fs::File; use std::io::{IoSlice, Write}; @@ -8,7 +9,7 @@ use base::libc::{ use base::{cstr, exit_on_error, open_fd, raw_cstr, FsPath, LogLevel, Logger, Utf8CStr, LOGGER}; // SAFETY: magiskinit is single threaded -static mut KMSG: Option = None; +static mut KMSG: UnsafeCell> = UnsafeCell::new(None); pub fn setup_klog() { unsafe { @@ -32,7 +33,7 @@ pub fn setup_klog() { fd = open_fd!(cstr!("/kmsg"), O_WRONLY | O_CLOEXEC); FsPath::from(cstr!("/kmsg")).remove().ok(); } - KMSG = fd.map(|fd| fd.into()).ok(); + *KMSG.get() = fd.map(|fd| fd.into()).ok(); } // Disable kmsg rate limiting @@ -45,7 +46,7 @@ pub fn setup_klog() { } fn kmsg_log_write(_: LogLevel, msg: &Utf8CStr) { - if let Some(kmsg) = unsafe { &mut KMSG } { + if let Some(kmsg) = unsafe { &mut *KMSG.get() } { let io1 = IoSlice::new("magiskinit: ".as_bytes()); let io2 = IoSlice::new(msg.as_bytes()); let _ = kmsg.write_vectored(&[io1, io2]).ok();