You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Remove open_fd macro
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
use base::{
|
||||
FsPath, LOGGER, LogLevel, Logger, Utf8CStr, cstr,
|
||||
FsPath, LOGGER, LogLevel, Logger, SilentResultExt, Utf8CStr, cstr,
|
||||
libc::{
|
||||
O_CLOEXEC, O_RDWR, O_WRONLY, S_IFCHR, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO, SYS_dup3,
|
||||
makedev, mknod, syscall,
|
||||
},
|
||||
open_fd, raw_cstr,
|
||||
raw_cstr,
|
||||
};
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{IoSlice, Write},
|
||||
mem,
|
||||
os::fd::{FromRawFd, IntoRawFd, RawFd},
|
||||
};
|
||||
|
||||
@@ -19,10 +19,10 @@ static mut KMSG: RawFd = -1;
|
||||
pub fn setup_klog() {
|
||||
unsafe {
|
||||
// Shut down first 3 fds
|
||||
let mut fd = open_fd!(cstr!("/dev/null"), O_RDWR | O_CLOEXEC);
|
||||
let mut fd = cstr!("/dev/null").open(O_RDWR | O_CLOEXEC).silent();
|
||||
if fd.is_err() {
|
||||
mknod(raw_cstr!("/null"), S_IFCHR | 0o666, makedev(1, 3));
|
||||
fd = open_fd!(cstr!("/null"), O_RDWR | O_CLOEXEC);
|
||||
fd = cstr!("/null").open(O_RDWR | O_CLOEXEC).silent();
|
||||
cstr!("/null").remove().ok();
|
||||
}
|
||||
if let Ok(ref fd) = fd {
|
||||
@@ -32,21 +32,17 @@ pub fn setup_klog() {
|
||||
}
|
||||
|
||||
// Then open kmsg fd
|
||||
let mut fd = open_fd!(cstr!("/dev/kmsg"), O_WRONLY | O_CLOEXEC);
|
||||
let mut fd = cstr!("/dev/kmsg").open(O_WRONLY | O_CLOEXEC).silent();
|
||||
if fd.is_err() {
|
||||
mknod(raw_cstr!("/kmsg"), S_IFCHR | 0o666, makedev(1, 11));
|
||||
fd = open_fd!(cstr!("/kmsg"), O_WRONLY | O_CLOEXEC);
|
||||
fd = cstr!("/kmsg").open(O_WRONLY | O_CLOEXEC).silent();
|
||||
cstr!("/kmsg").remove().ok();
|
||||
}
|
||||
KMSG = fd.map(|fd| fd.into_raw_fd()).unwrap_or(-1);
|
||||
}
|
||||
|
||||
// Disable kmsg rate limiting
|
||||
if let Ok(rate) = open_fd!(
|
||||
cstr!("/proc/sys/kernel/printk_devkmsg"),
|
||||
O_WRONLY | O_CLOEXEC
|
||||
) {
|
||||
let mut rate = File::from(rate);
|
||||
if let Ok(mut rate) = cstr!("/proc/sys/kernel/printk_devkmsg").open(O_WRONLY | O_CLOEXEC) {
|
||||
writeln!(rate, "on").ok();
|
||||
}
|
||||
|
||||
@@ -55,9 +51,8 @@ pub fn setup_klog() {
|
||||
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 mut kmsg = ManuallyDrop::new(unsafe { File::from_raw_fd(fd) });
|
||||
let _ = kmsg.write_vectored(&[io1, io2]).ok();
|
||||
mem::forget(kmsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user