fix shitcode

This commit is contained in:
sqlerrorthing
2025-11-03 05:10:52 +08:00
parent 8a1d336e4b
commit aa1788386a

View File

@@ -8,8 +8,7 @@ use nix::sys::signal::{Signal, kill};
use nix::unistd::{Pid, Uid};
use regex::Regex;
use std::borrow::Cow;
use std::path::Path;
use sysctl::Sysctl;
use sysctl::{Ctl, CtlValue, Sysctl};
use sysinfo::{Pid as SysPid, System};
use tokio::fs;
use tokio::fs::File;
@@ -62,8 +61,8 @@ pub async fn start_service() -> anyhow::Result<()> {
.replace_all(&strat_modified, ZAPRETT_DIR_PATH.to_str().unwrap())
.into_owned();
let ctl = sysctl::Ctl::new("net.netfilter.nf_conntrack_tcp_be_liberal")?;
ctl.set_value(sysctl::CtlValue::String("1".into()))?;
let ctl = Ctl::new("net.netfilter.nf_conntrack_tcp_be_liberal")?;
ctl.set_value(CtlValue::String("1".into()))?;
setup_iptables_rules().expect("setup iptables rules");
@@ -106,19 +105,17 @@ pub async fn service_status() -> anyhow::Result<bool> {
bail!("Running not from root, exiting");
};
let pid_i32 = match fs::read_to_string(Path::new(*MODULE_PATH).join("tmp/pid.lock")).await {
Ok(s) => match s.trim().parse::<i32>() {
Ok(pid) => pid,
Err(_) => return Ok(false),
},
Err(_) => return Ok(false),
let Ok(Some(pid)) = fs::read_to_string(MODULE_PATH.join("/tmp/pid.lock"))
.await
.map(|s| s.trim().parse::<usize>().ok())
else {
bail!("failed to get pid");
};
let pid = SysPid::from(pid_i32 as usize);
let system = System::new_all();
if let Some(process) = system.process(pid) {
if process.name() == "zaprett" {
return Ok(true);
}
}
Ok(false)
let is_zaprett = System::new_all()
.process(SysPid::from(pid))
.map(|process| process.name() == "zaprett")
.unwrap_or(false);
Ok(is_zaprett)
}