Use const_format for const strings

This commit is contained in:
topjohnwu
2024-03-26 18:03:40 -07:00
parent 21ed095601
commit 1eddbfd72c
8 changed files with 79 additions and 68 deletions

View File

@@ -17,4 +17,5 @@ cxx = { workspace = true }
num-traits = { workspace = true }
num-derive = { workspace = true }
quick-protobuf = { workspace = true }
const_format = { workspace = true }
bytemuck = { workspace = true, features = ["derive"] }

View File

@@ -9,9 +9,10 @@ use base::{
Utf8CStrBufArr, Utf8CStrBufRef, WalkResult,
};
use crate::consts::MAIN_CONFIG;
use crate::ffi::{get_magisk_tmp, CxxMagiskD, RequestCode};
use crate::get_prop;
use crate::logging::magisk_logging;
use crate::{get_prop, MAIN_CONFIG};
// Global magiskd singleton
pub static MAGISKD: OnceLock<MagiskD> = OnceLock::new();
@@ -108,7 +109,7 @@ pub fn daemon_entry() {
let mut buf = Utf8CStrBufArr::<64>::new();
let path = FsPathBuf::new(&mut buf)
.join(get_magisk_tmp())
.join(MAIN_CONFIG!());
.join(MAIN_CONFIG);
let mut is_recovery = false;
if let Ok(file) = path.open(O_RDONLY | O_CLOEXEC) {
let mut file = BufReader::new(file);

View File

@@ -9,6 +9,7 @@ use std::sync::atomic::{AtomicI32, Ordering};
use std::{fs, io};
use bytemuck::{bytes_of, bytes_of_mut, write_zeroes, Pod, Zeroable};
use const_format::concatcp;
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::FromPrimitive;
@@ -17,12 +18,15 @@ use base::libc::{
timespec, tm, CLOCK_REALTIME, O_CLOEXEC, O_RDWR, O_WRONLY, PIPE_BUF, SIGPIPE, SIG_BLOCK,
SIG_SETMASK,
};
use base::*;
use base::{
exit_on_error, libc, raw_cstr, FsPathBuf, LogLevel, Logger, Utf8CStr, Utf8CStrBuf,
Utf8CStrBufArr, Utf8CStrWrite, LOGGER,
};
use crate::consts::{LOGFILE, LOG_PIPE};
use crate::daemon::{MagiskD, MAGISKD};
use crate::ffi::get_magisk_tmp;
use crate::logging::LogFile::{Actual, Buffer};
use crate::{LOGFILE, LOG_PIPE};
#[allow(dead_code, non_camel_case_types)]
#[derive(FromPrimitive, ToPrimitive)]
@@ -192,7 +196,7 @@ pub fn zygisk_get_logd() -> i32 {
let mut buf = Utf8CStrBufArr::default();
let path = FsPathBuf::new(&mut buf)
.join(get_magisk_tmp())
.join(LOG_PIPE!());
.join(LOG_PIPE);
// Open as RW as sometimes it may block
fd = unsafe { libc::open(path.as_ptr(), O_RDWR | O_CLOEXEC) };
if fd >= 0 {
@@ -292,9 +296,9 @@ extern "C" fn logfile_writer(arg: *mut c_void) -> *mut c_void {
pipe.read_exact(bytes_of_mut(&mut meta))?;
if meta.prio < 0 {
if matches!(logfile, LogFile::Buffer(_)) {
fs::rename(LOGFILE!(), concat!(LOGFILE!(), ".bak")).ok();
let mut out = File::create(LOGFILE!())?;
if matches!(logfile, Buffer(_)) {
fs::rename(LOGFILE, concatcp!(LOGFILE, ".bak")).ok();
let mut out = File::create(LOGFILE)?;
out.write_all(tmp.as_slice())?;
tmp = Vec::new();
logfile = Actual(out);
@@ -371,7 +375,7 @@ impl MagiskD {
let mut buf = Utf8CStrBufArr::default();
let path = FsPathBuf::new(&mut buf)
.join(get_magisk_tmp())
.join(LOG_PIPE!());
.join(LOG_PIPE);
unsafe {
libc::mkfifo(path.as_ptr(), 0o666);