mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Resolve clippy errors and warnings
This commit is contained in:
parent
665c6bdc4b
commit
9ea9f01933
@ -21,7 +21,7 @@ pub mod unsafe_impl {
|
||||
if r >= 0 {
|
||||
*buf.offset(r) = b'\0';
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -42,12 +42,14 @@ pub fn __open_fd_impl(path: &CStr, flags: i32, mode: mode_t) -> Option<OwnedFd>
|
||||
}
|
||||
|
||||
pub fn __xopen_fd_impl(path: &CStr, flags: i32, mode: mode_t) -> Option<OwnedFd> {
|
||||
unsafe {
|
||||
let fd = xopen(path.as_ptr(), flags, mode);
|
||||
if fd >= 0 {
|
||||
unsafe { Some(OwnedFd::from_raw_fd(fd)) }
|
||||
Some(OwnedFd::from_raw_fd(fd))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@ -87,7 +89,7 @@ pub fn realpath(path: &CStr, buf: &mut [u8]) -> isize {
|
||||
let mut st2: libc::stat;
|
||||
let mut skip_check = false;
|
||||
unsafe {
|
||||
st1 = std::mem::zeroed();
|
||||
st1 = mem::zeroed();
|
||||
if libc::fstat(fd.as_raw_fd(), &mut st1) < 0 {
|
||||
// This shall only fail on Linux < 3.6
|
||||
skip_check = true;
|
||||
@ -95,7 +97,7 @@ pub fn realpath(path: &CStr, buf: &mut [u8]) -> isize {
|
||||
}
|
||||
let len = fd_path(fd.as_raw_fd(), buf);
|
||||
unsafe {
|
||||
st2 = std::mem::zeroed();
|
||||
st2 = mem::zeroed();
|
||||
if libc::stat(buf.as_ptr().cast(), &mut st2) < 0
|
||||
|| (!skip_check && (st2.st_dev != st1.st_dev || st2.st_ino != st1.st_ino))
|
||||
{
|
||||
@ -103,7 +105,7 @@ pub fn realpath(path: &CStr, buf: &mut [u8]) -> isize {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
len
|
||||
} else {
|
||||
*errno() = ENOENT;
|
||||
-1
|
||||
@ -115,9 +117,8 @@ extern "C" {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mkdirs(path: *const c_char, mode: mode_t) -> i32 {
|
||||
unsafe {
|
||||
let mut buf = [0 as u8; 4096];
|
||||
pub unsafe extern "C" fn mkdirs(path: *const c_char, mode: mode_t) -> i32 {
|
||||
let mut buf = [0_u8; 4096];
|
||||
let ptr: *mut c_char = buf.as_mut_ptr().cast();
|
||||
let len = strscpy(ptr, path, buf.len());
|
||||
let mut curr = &mut buf[1..len];
|
||||
@ -133,7 +134,6 @@ pub extern "C" fn mkdirs(path: *const c_char, mode: mode_t) -> i32 {
|
||||
return -1;
|
||||
}
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ReadExt {
|
||||
@ -201,7 +201,7 @@ impl<T: BufRead> BufReadExt for T {
|
||||
if let Some((key, value)) = line.split_once('=') {
|
||||
return f(key, value);
|
||||
}
|
||||
return true;
|
||||
true
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -212,10 +212,10 @@ pub trait WriteExt {
|
||||
|
||||
impl<T: Write> WriteExt for T {
|
||||
fn write_zeros(&mut self, mut len: usize) -> io::Result<()> {
|
||||
let mut buf = [0 as u8; 4096];
|
||||
let buf = [0_u8; 4096];
|
||||
while len > 0 {
|
||||
let l = min(buf.len(), len);
|
||||
self.write_all(&mut buf[..l])?;
|
||||
self.write_all(&buf[..l])?;
|
||||
len -= l;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
#![feature(format_args_nl)]
|
||||
#![feature(io_error_more)]
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub fn exit_on_error(b: bool) {
|
||||
}
|
||||
|
||||
impl LogLevel {
|
||||
fn to_disable_flag(&self) -> u32 {
|
||||
fn as_disable_flag(&self) -> u32 {
|
||||
match *self {
|
||||
LogLevel::Error => LogFlag::DisableError,
|
||||
LogLevel::Warn => LogFlag::DisableWarn,
|
||||
@ -51,7 +51,7 @@ impl LogLevel {
|
||||
}
|
||||
|
||||
pub fn set_log_level_state(level: LogLevel, enabled: bool) {
|
||||
let flag = level.to_disable_flag();
|
||||
let flag = level.as_disable_flag();
|
||||
unsafe {
|
||||
if enabled {
|
||||
LOGGER.flags &= !flag
|
||||
@ -63,7 +63,7 @@ pub fn set_log_level_state(level: LogLevel, enabled: bool) {
|
||||
|
||||
pub fn log_with_rs(level: LogLevel, msg: &[u8]) {
|
||||
let logger = unsafe { LOGGER };
|
||||
if (logger.flags & level.to_disable_flag()) != 0 {
|
||||
if (logger.flags & level.as_disable_flag()) != 0 {
|
||||
return;
|
||||
}
|
||||
(logger.write)(level, msg);
|
||||
@ -74,7 +74,7 @@ pub fn log_with_rs(level: LogLevel, msg: &[u8]) {
|
||||
|
||||
pub fn log_impl(level: LogLevel, args: Arguments) {
|
||||
let logger = unsafe { LOGGER };
|
||||
if (logger.flags & level.to_disable_flag()) != 0 {
|
||||
if (logger.flags & level.as_disable_flag()) != 0 {
|
||||
return;
|
||||
}
|
||||
let mut buf: [u8; 4096] = [0; 4096];
|
||||
@ -108,16 +108,16 @@ macro_rules! perror {
|
||||
($fmt:expr) => {
|
||||
$crate::log_impl($crate::ffi::LogLevel::Error, format_args_nl!(
|
||||
concat!($fmt, " failed with {}: {}"),
|
||||
crate::errno(),
|
||||
crate::error_str()
|
||||
$crate::errno(),
|
||||
$crate::error_str()
|
||||
))
|
||||
};
|
||||
($fmt:expr, $($args:tt)*) => {
|
||||
$crate::log_impl($crate::ffi::LogLevel::Error, format_args_nl!(
|
||||
concat!($fmt, " failed with {}: {}"),
|
||||
$($args)*,
|
||||
crate::errno(),
|
||||
crate::error_str()
|
||||
$crate::errno(),
|
||||
$crate::error_str()
|
||||
))
|
||||
};
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ pub fn ptr_to_str_result<'a, T>(ptr: *const T) -> Result<&'a str, StrErr> {
|
||||
} else {
|
||||
unsafe { CStr::from_ptr(ptr.cast()) }
|
||||
.to_str()
|
||||
.map_err(|e| StrErr::from(e))
|
||||
.map_err(StrErr::from)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ use libc::{
|
||||
ssize_t, SYS_dup3,
|
||||
};
|
||||
|
||||
use crate::{cstr, errno, error, mkdirs, perror, ptr_to_str, realpath};
|
||||
use crate::{cstr, errno, error, mkdirs, perror, ptr_to_str, raw_cstr, realpath};
|
||||
|
||||
mod unsafe_impl {
|
||||
use std::ffi::CStr;
|
||||
@ -45,7 +45,7 @@ mod unsafe_impl {
|
||||
if r < 0 {
|
||||
perror!("readlink");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -73,7 +73,7 @@ mod unsafe_impl {
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -82,7 +82,7 @@ mod unsafe_impl {
|
||||
if r < 0 {
|
||||
perror!("poll");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -96,52 +96,49 @@ mod unsafe_impl {
|
||||
if r < 0 {
|
||||
perror!("sendfile");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xfopen(path: *const c_char, mode: *const c_char) -> *mut libc::FILE {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xfopen(path: *const c_char, mode: *const c_char) -> *mut libc::FILE {
|
||||
let fp = libc::fopen(path, mode);
|
||||
if fp.is_null() {
|
||||
perror!("fopen {}", ptr_to_str(path));
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
fp
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xfdopen(fd: RawFd, mode: *const c_char) -> *mut libc::FILE {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xfdopen(fd: RawFd, mode: *const c_char) -> *mut libc::FILE {
|
||||
let fp = libc::fdopen(fd, mode);
|
||||
if fp.is_null() {
|
||||
perror!("fdopen");
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
fp
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xopen(path: *const c_char, flags: i32, mode: mode_t) -> RawFd {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xopen(path: *const c_char, flags: i32, mode: mode_t) -> RawFd {
|
||||
let r = libc::open(path, flags, mode as c_uint);
|
||||
if r < 0 {
|
||||
perror!("open {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xopenat(dirfd: RawFd, path: *const c_char, flags: i32, mode: mode_t) -> RawFd {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xopenat(
|
||||
dirfd: RawFd,
|
||||
path: *const c_char,
|
||||
flags: i32,
|
||||
mode: mode_t,
|
||||
) -> RawFd {
|
||||
let r = libc::openat(dirfd, path, flags, mode as c_uint);
|
||||
if r < 0 {
|
||||
perror!("openat {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
// Fully write data slice
|
||||
@ -157,19 +154,19 @@ pub fn xwrite(fd: RawFd, data: &[u8]) -> isize {
|
||||
continue;
|
||||
}
|
||||
perror!("write");
|
||||
return r as isize;
|
||||
return r;
|
||||
}
|
||||
let r = r as usize;
|
||||
write_sz += r;
|
||||
remain = &remain[r..];
|
||||
if r == 0 || remain.len() == 0 {
|
||||
if r == 0 || remain.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if remain.len() != 0 {
|
||||
if !remain.is_empty() {
|
||||
error!("write ({} != {})", write_sz, data.len())
|
||||
}
|
||||
return write_sz as isize;
|
||||
write_sz as isize
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +176,7 @@ pub fn xread(fd: RawFd, data: &mut [u8]) -> isize {
|
||||
if r < 0 {
|
||||
perror!("read");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,19 +193,19 @@ pub fn xxread(fd: RawFd, data: &mut [u8]) -> isize {
|
||||
continue;
|
||||
}
|
||||
perror!("read");
|
||||
return r as isize;
|
||||
return r;
|
||||
}
|
||||
let r = r as usize;
|
||||
read_sz += r;
|
||||
remain = &mut remain[r..];
|
||||
if r == 0 || remain.len() == 0 {
|
||||
if r == 0 || remain.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if remain.len() != 0 {
|
||||
if !remain.is_empty() {
|
||||
error!("read ({} != {})", read_sz, data.len())
|
||||
}
|
||||
return read_sz as isize;
|
||||
read_sz as isize
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +216,7 @@ pub extern "C" fn xlseek64(fd: RawFd, offset: i64, whence: i32) -> i64 {
|
||||
if r < 0 {
|
||||
perror!("lseek64");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +226,7 @@ pub fn xpipe2(fds: &mut [i32; 2], flags: i32) -> i32 {
|
||||
if r < 0 {
|
||||
perror!("pipe2");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,7 +237,7 @@ pub extern "C" fn xsetns(fd: RawFd, nstype: i32) -> i32 {
|
||||
if r < 0 {
|
||||
perror!("setns");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,19 +248,17 @@ pub extern "C" fn xunshare(flags: i32) -> i32 {
|
||||
if r < 0 {
|
||||
perror!("unshare");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xopendir(path: *const c_char) -> *mut libc::DIR {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xopendir(path: *const c_char) -> *mut libc::DIR {
|
||||
let dp = libc::opendir(path);
|
||||
if dp.is_null() {
|
||||
perror!("opendir {}", ptr_to_str(path));
|
||||
}
|
||||
return dp;
|
||||
}
|
||||
dp
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -273,14 +268,12 @@ pub extern "C" fn xfdopendir(fd: RawFd) -> *mut libc::DIR {
|
||||
if dp.is_null() {
|
||||
perror!("fdopendir");
|
||||
}
|
||||
return dp;
|
||||
dp
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xreaddir(dirp: *mut libc::DIR) -> *mut libc::dirent {
|
||||
#[allow(unused_unsafe)]
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xreaddir(dirp: *mut libc::DIR) -> *mut libc::dirent {
|
||||
*errno() = 0;
|
||||
loop {
|
||||
let e = libc::readdir(dirp);
|
||||
@ -290,14 +283,13 @@ pub extern "C" fn xreaddir(dirp: *mut libc::DIR) -> *mut libc::dirent {
|
||||
}
|
||||
} else {
|
||||
// Filter out . and ..
|
||||
let s = CStr::from_ptr((*e).d_name.as_ptr());
|
||||
if s == cstr!(".") || s == cstr!("..") {
|
||||
let s = (*e).d_name.as_ptr();
|
||||
if libc::strcmp(s, raw_cstr!(".")) == 0 || libc::strcmp(s, raw_cstr!("..")) == 0 {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -307,7 +299,7 @@ pub extern "C" fn xsetsid() -> i32 {
|
||||
if r < 0 {
|
||||
perror!("setsid");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,19 +310,17 @@ pub extern "C" fn xsocket(domain: i32, ty: i32, protocol: i32) -> RawFd {
|
||||
if fd < 0 {
|
||||
perror!("socket");
|
||||
}
|
||||
return fd;
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xbind(socket: i32, address: *const sockaddr, len: socklen_t) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xbind(socket: i32, address: *const sockaddr, len: socklen_t) -> i32 {
|
||||
let r = libc::bind(socket, address, len);
|
||||
if r < 0 {
|
||||
perror!("bind");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -340,62 +330,58 @@ pub extern "C" fn xlisten(socket: i32, backlog: i32) -> i32 {
|
||||
if r < 0 {
|
||||
perror!("listen");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xaccept4(
|
||||
pub unsafe extern "C" fn xaccept4(
|
||||
sockfd: RawFd,
|
||||
addr: *mut sockaddr,
|
||||
len: *mut socklen_t,
|
||||
flg: i32,
|
||||
) -> RawFd {
|
||||
unsafe {
|
||||
let fd = libc::accept4(sockfd, addr, len, flg);
|
||||
if fd < 0 {
|
||||
perror!("accept4");
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
fd
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xsendmsg(fd: RawFd, msg: *const libc::msghdr, flags: i32) -> ssize_t {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xsendmsg(fd: RawFd, msg: *const libc::msghdr, flags: i32) -> ssize_t {
|
||||
let r = libc::sendmsg(fd, msg, flags);
|
||||
if r < 0 {
|
||||
perror!("sendmsg");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xrecvmsg(fd: RawFd, msg: *mut libc::msghdr, flags: i32) -> ssize_t {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xrecvmsg(fd: RawFd, msg: *mut libc::msghdr, flags: i32) -> ssize_t {
|
||||
let r = libc::recvmsg(fd, msg, flags);
|
||||
if r < 0 {
|
||||
perror!("recvmsg");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xaccess(path: *const c_char, mode: i32) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xaccess(path: *const c_char, mode: i32) -> i32 {
|
||||
let r = libc::access(path, mode);
|
||||
if r < 0 {
|
||||
perror!("access {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xfaccessat(dirfd: RawFd, path: *const c_char, mode: i32, flags: i32) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xfaccessat(
|
||||
dirfd: RawFd,
|
||||
path: *const c_char,
|
||||
mode: i32,
|
||||
flags: i32,
|
||||
) -> i32 {
|
||||
#[allow(unused_mut)]
|
||||
let mut r = libc::faccessat(dirfd, path, mode, flags);
|
||||
if r < 0 {
|
||||
@ -405,57 +391,48 @@ pub extern "C" fn xfaccessat(dirfd: RawFd, path: *const c_char, mode: i32, flags
|
||||
if r > 0 && *errno() == 0 {
|
||||
r = 0
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
let r = libc::stat(path, buf);
|
||||
if r < 0 {
|
||||
perror!("stat {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xlstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xlstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
let r = libc::lstat(path, buf);
|
||||
if r < 0 {
|
||||
perror!("lstat {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xfstat(fd: RawFd, buf: *mut libc::stat) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xfstat(fd: RawFd, buf: *mut libc::stat) -> i32 {
|
||||
let r = libc::fstat(fd, buf);
|
||||
if r < 0 {
|
||||
perror!("fstat");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xfstatat(
|
||||
pub unsafe extern "C" fn xfstatat(
|
||||
dirfd: RawFd,
|
||||
path: *const c_char,
|
||||
buf: *mut libc::stat,
|
||||
flags: i32,
|
||||
) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::fstatat(dirfd, path, buf, flags);
|
||||
if r < 0 {
|
||||
perror!("fstatat {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -465,7 +442,7 @@ pub extern "C" fn xdup(oldfd: RawFd) -> RawFd {
|
||||
if fd < 0 {
|
||||
perror!("dup");
|
||||
}
|
||||
return fd;
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,7 +453,7 @@ pub extern "C" fn xdup2(oldfd: RawFd, newfd: RawFd) -> RawFd {
|
||||
if fd < 0 {
|
||||
perror!("dup2");
|
||||
}
|
||||
return fd;
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
@ -487,7 +464,7 @@ pub extern "C" fn xdup3(oldfd: RawFd, newfd: RawFd, flags: i32) -> RawFd {
|
||||
if fd < 0 {
|
||||
perror!("dup3");
|
||||
}
|
||||
return fd;
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
@ -502,19 +479,20 @@ pub fn xreadlinkat(dirfd: RawFd, path: &CStr, data: &mut [u8]) -> isize {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xsymlink(target: *const c_char, linkpath: *const c_char) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xsymlink(target: *const c_char, linkpath: *const c_char) -> i32 {
|
||||
let r = libc::symlink(target, linkpath);
|
||||
if r < 0 {
|
||||
perror!("symlink {} -> {}", ptr_to_str(target), ptr_to_str(linkpath));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xsymlinkat(target: *const c_char, dirfd: RawFd, linkpath: *const c_char) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xsymlinkat(
|
||||
target: *const c_char,
|
||||
dirfd: RawFd,
|
||||
linkpath: *const c_char,
|
||||
) -> i32 {
|
||||
let r = libc::symlinkat(target, dirfd, linkpath);
|
||||
if r < 0 {
|
||||
perror!(
|
||||
@ -523,106 +501,91 @@ pub extern "C" fn xsymlinkat(target: *const c_char, dirfd: RawFd, linkpath: *con
|
||||
ptr_to_str(linkpath)
|
||||
);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xlinkat(
|
||||
pub unsafe extern "C" fn xlinkat(
|
||||
olddirfd: RawFd,
|
||||
target: *const c_char,
|
||||
newdirfd: RawFd,
|
||||
linkpath: *const c_char,
|
||||
flags: i32,
|
||||
) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::linkat(olddirfd, target, newdirfd, linkpath, flags);
|
||||
if r < 0 {
|
||||
perror!("linkat {} -> {}", ptr_to_str(target), ptr_to_str(linkpath));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xmount(
|
||||
pub unsafe extern "C" fn xmount(
|
||||
src: *const c_char,
|
||||
target: *const c_char,
|
||||
fstype: *const c_char,
|
||||
flags: c_ulong,
|
||||
data: *const c_void,
|
||||
) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::mount(src, target, fstype, flags, data);
|
||||
if r < 0 {
|
||||
perror!("mount {} -> {}", ptr_to_str(src), ptr_to_str(target));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xumount(target: *const c_char) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xumount(target: *const c_char) -> i32 {
|
||||
let r = libc::umount(target);
|
||||
if r < 0 {
|
||||
perror!("umount {}", ptr_to_str(target));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xumount2(target: *const c_char, flags: i32) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xumount2(target: *const c_char, flags: i32) -> i32 {
|
||||
let r = libc::umount2(target, flags);
|
||||
if r < 0 {
|
||||
perror!("umount2 {}", ptr_to_str(target));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xrename(oldname: *const c_char, newname: *const c_char) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xrename(oldname: *const c_char, newname: *const c_char) -> i32 {
|
||||
let r = libc::rename(oldname, newname);
|
||||
if r < 0 {
|
||||
perror!("rename {} -> {}", ptr_to_str(oldname), ptr_to_str(newname));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xmkdir(path: *const c_char, mode: mode_t) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xmkdir(path: *const c_char, mode: mode_t) -> i32 {
|
||||
let r = libc::mkdir(path, mode);
|
||||
if r < 0 && *errno() != libc::EEXIST {
|
||||
perror!("mkdir {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xmkdirs(path: *const c_char, mode: mode_t) -> i32 {
|
||||
pub unsafe extern "C" fn xmkdirs(path: *const c_char, mode: mode_t) -> i32 {
|
||||
let r = mkdirs(path, mode);
|
||||
if r < 0 {
|
||||
perror!("mkdirs {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xmkdirat(dirfd: RawFd, path: *const c_char, mode: mode_t) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xmkdirat(dirfd: RawFd, path: *const c_char, mode: mode_t) -> i32 {
|
||||
let r = libc::mkdirat(dirfd, path, mode);
|
||||
if r < 0 && *errno() != libc::EEXIST {
|
||||
perror!("mkdirat {}", ptr_to_str(path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -634,7 +597,7 @@ pub fn xsendfile(out_fd: RawFd, in_fd: RawFd, offset: Option<&mut off_t>, count:
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xmmap(
|
||||
pub unsafe extern "C" fn xmmap(
|
||||
addr: *mut c_void,
|
||||
len: usize,
|
||||
prot: i32,
|
||||
@ -642,14 +605,12 @@ pub extern "C" fn xmmap(
|
||||
fd: RawFd,
|
||||
offset: off_t,
|
||||
) -> *mut c_void {
|
||||
unsafe {
|
||||
let r = libc::mmap(addr, len, prot, flags, fd, offset);
|
||||
if r == libc::MAP_FAILED {
|
||||
perror!("mmap");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -659,7 +620,7 @@ pub extern "C" fn xfork() -> i32 {
|
||||
if r < 0 {
|
||||
perror!("fork");
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
@ -673,16 +634,14 @@ pub fn xrealpath(path: &CStr, buf: &mut [u8]) -> isize {
|
||||
if r < 0 {
|
||||
perror!("realpath {}", path.to_str().unwrap_or(""))
|
||||
}
|
||||
return r;
|
||||
r
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn xmknod(pathname: *const c_char, mode: mode_t, dev: dev_t) -> i32 {
|
||||
unsafe {
|
||||
pub unsafe extern "C" fn xmknod(pathname: *const c_char, mode: mode_t, dev: dev_t) -> i32 {
|
||||
let r = libc::mknod(pathname, mode, dev);
|
||||
if r < 0 {
|
||||
perror!("mknod {}", ptr_to_str(pathname));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
|
||||
use daemon::*;
|
||||
use logging::*;
|
||||
use std::ffi::CStr;
|
||||
|
@ -78,7 +78,7 @@ pub fn magisk_logging() {
|
||||
unsafe {
|
||||
__android_log_write(level_to_prio(level), raw_cstr!("Magisk"), msg.as_ptr());
|
||||
}
|
||||
magisk_log_write(level_to_prio(level), &msg);
|
||||
magisk_log_write(level_to_prio(level), msg);
|
||||
}
|
||||
|
||||
let logger = Logger {
|
||||
@ -96,7 +96,7 @@ pub fn zygisk_logging() {
|
||||
unsafe {
|
||||
__android_log_write(level_to_prio(level), raw_cstr!("Magisk"), msg.as_ptr());
|
||||
}
|
||||
zygisk_log_write(level_to_prio(level), &msg);
|
||||
zygisk_log_write(level_to_prio(level), msg);
|
||||
}
|
||||
|
||||
let logger = Logger {
|
||||
@ -150,7 +150,7 @@ fn magisk_log_write(prio: i32, msg: &[u8]) {
|
||||
Some(s) => s,
|
||||
};
|
||||
|
||||
let result = do_magisk_log_write(logd, prio, &msg);
|
||||
let result = do_magisk_log_write(logd, prio, msg);
|
||||
|
||||
// If any error occurs, shut down the logd pipe
|
||||
if result.is_err() {
|
||||
@ -190,7 +190,7 @@ fn zygisk_log_write(prio: i32, msg: &[u8]) {
|
||||
pthread_sigmask(SIG_BLOCK, &mask, &mut orig_mask);
|
||||
}
|
||||
|
||||
let result = do_magisk_log_write(logd, prio, &msg);
|
||||
let result = do_magisk_log_write(logd, prio, msg);
|
||||
|
||||
// Consume SIGPIPE if exists, then restore mask
|
||||
unsafe {
|
||||
@ -278,7 +278,7 @@ extern "C" fn logfile_writer(arg: *mut c_void) -> *mut c_void {
|
||||
let mut ts: timespec = std::mem::zeroed();
|
||||
let mut tm: tm = std::mem::zeroed();
|
||||
if clock_gettime(CLOCK_REALTIME, &mut ts) < 0
|
||||
|| localtime_r(&ts.tv_sec, &mut tm) == null_mut()
|
||||
|| localtime_r(&ts.tv_sec, &mut tm).is_null()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -301,7 +301,9 @@ extern "C" fn logfile_writer(arg: *mut c_void) -> *mut c_void {
|
||||
|
||||
let io1 = IoSlice::new(&aux[..aux_len]);
|
||||
let io2 = IoSlice::new(msg);
|
||||
logfile.as_write().write_vectored(&[io1, io2])?;
|
||||
// We don't need to care the written len because we are writing less than PIPE_BUF
|
||||
// It's guaranteed to always write the whole thing atomically
|
||||
let _ = logfile.as_write().write_vectored(&[io1, io2])?;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user