mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-05 20:40:19 -08:00
Cleanup code
This commit is contained in:
@@ -16,7 +16,7 @@ use nix::fcntl::OFlag;
|
|||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use nix::{
|
|||||||
};
|
};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::mem::{ManuallyDrop, MaybeUninit};
|
use std::mem::MaybeUninit;
|
||||||
use std::os::fd::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd};
|
use std::os::fd::{AsFd, AsRawFd, FromRawFd, RawFd};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
static SHOULD_USE_SPLICE: AtomicBool = AtomicBool::new(true);
|
static SHOULD_USE_SPLICE: AtomicBool = AtomicBool::new(true);
|
||||||
@@ -50,7 +50,7 @@ fn pump_via_copy(mut fd_in: &File, mut fd_out: &File) -> LoggedResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pump_via_splice(fd_in: &File, fd_out: &File, pipe: &(OwnedFd, OwnedFd)) -> LoggedResult<()> {
|
fn pump_via_splice(fd_in: &File, fd_out: &File, pipe: &(File, File)) -> LoggedResult<()> {
|
||||||
if !SHOULD_USE_SPLICE.load(Ordering::Relaxed) {
|
if !SHOULD_USE_SPLICE.load(Ordering::Relaxed) {
|
||||||
return pump_via_copy(fd_in, fd_out);
|
return pump_via_copy(fd_in, fd_out);
|
||||||
}
|
}
|
||||||
@@ -64,10 +64,10 @@ fn pump_via_splice(fd_in: &File, fd_out: &File, pipe: &(OwnedFd, OwnedFd)) -> Lo
|
|||||||
if len == 0 {
|
if len == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if let Err(_) = splice(&pipe.0, fd_out, len) {
|
if splice(&pipe.0, fd_out, len).is_err() {
|
||||||
// If splice failed, stop using splice and fallback to userspace copy
|
// If splice failed, stop using splice and fallback to userspace copy
|
||||||
SHOULD_USE_SPLICE.store(false, Ordering::Relaxed);
|
SHOULD_USE_SPLICE.store(false, Ordering::Relaxed);
|
||||||
return pump_via_copy(&ManuallyDrop::new(unsafe { File::from_raw_fd(pipe.0.as_raw_fd()) }), fd_out);
|
return pump_via_copy(&pipe.0, fd_out);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -132,6 +132,7 @@ fn pump_tty_impl(ptmx: File, pump_stdin: bool) -> LoggedResult<()> {
|
|||||||
|
|
||||||
// Open a pipe to bypass userspace copy with splice
|
// Open a pipe to bypass userspace copy with splice
|
||||||
let pipe_fd = pipe2(OFlag::O_CLOEXEC).into_os_result("pipe2", None, None)?;
|
let pipe_fd = pipe2(OFlag::O_CLOEXEC).into_os_result("pipe2", None, None)?;
|
||||||
|
let pipe_fd = (File::from(pipe_fd.0), File::from(pipe_fd.1));
|
||||||
|
|
||||||
'poll: loop {
|
'poll: loop {
|
||||||
// Wait for event
|
// Wait for event
|
||||||
|
|||||||
Reference in New Issue
Block a user