linux's dns hook is ok

This commit is contained in:
alex 2026-04-15 11:37:10 +08:00
parent 777d3bbc63
commit c5f5ea433a
2 changed files with 15 additions and 2 deletions

View File

@ -35,6 +35,7 @@ use sdlan_sn_rs::utils::Mac;
use sdlan_sn_rs::utils::Result; use sdlan_sn_rs::utils::Result;
use sdlan_sn_rs::utils::create_or_load_uuid; use sdlan_sn_rs::utils::create_or_load_uuid;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tracing::debug;
use tracing::error; use tracing::error;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
@ -248,13 +249,14 @@ async fn daemonize_me(
let mut started = true; let mut started = true;
*/ */
println!("waiting for ctrl-c");
match tokio::signal::ctrl_c().await { match tokio::signal::ctrl_c().await {
Ok(()) => { Ok(()) => {
edge.quic_endpoint.close(0u32.into(), "bye".as_bytes()); edge.quic_endpoint.close(0u32.into(), "bye".as_bytes());
println!("quic is quitting"); println!("quic is quitting");
delete_pid_file(); delete_pid_file();
let _ = restore_dns(); let _ = restore_dns();
debug!("restored dns");
} }
Err(err) => { Err(err) => {
eprintln!("failed to listen for shutdown signal: {}", err); eprintln!("failed to listen for shutdown signal: {}", err);
@ -360,7 +362,9 @@ fn main() {
} }
}; };
let result = unsafe { let result = unsafe {
kill(pid, SIGTERM) use libc::SIGINT;
kill(pid, SIGINT)
}; };
if result != 0 { if result != 0 {
let err = io::Error::last_os_error(); let err = io::Error::last_os_error();

View File

@ -858,6 +858,7 @@ pub fn get_install_channel() -> String {
} }
fn check_has_resolvectl() -> bool { fn check_has_resolvectl() -> bool {
return false;
let res = Command::new("resolvectl") let res = Command::new("resolvectl")
.arg("status") .arg("status")
.output(); .output();
@ -947,10 +948,15 @@ pub fn modify_resolv_conf(new_nameservers: &[String], search_domain: &str, keep_
let reader = BufReader::new(file); let reader = BufReader::new(file);
let mut lines = Vec::new(); let mut lines = Vec::new();
for ns in new_nameservers {
lines.push(format!("nameserver {}", ns))
}
/*
let mut inserted = false; let mut inserted = false;
let mut encounted_nameserver = false; let mut encounted_nameserver = false;
let mut search_added = false; let mut search_added = false;
for line in reader.lines() { for line in reader.lines() {
let line = line?; let line = line?;
let trimmed = line.trim(); let trimmed = line.trim();
@ -982,6 +988,7 @@ pub fn modify_resolv_conf(new_nameservers: &[String], search_domain: &str, keep_
if !search_added { if !search_added {
lines.push(format!("search {}", search_domain)); lines.push(format!("search {}", search_domain));
} }
*/
// 原子写入:先写临时文件 // 原子写入:先写临时文件
let tmp_dir = Path::new("/etc"); let tmp_dir = Path::new("/etc");
@ -992,6 +999,8 @@ pub fn modify_resolv_conf(new_nameservers: &[String], search_domain: &str, keep_
} }
tmp_file.flush()?; tmp_file.flush()?;
debug!("added to /etc/resolve.conf: {:?}", lines);
// 设置权限 // 设置权限
fs::set_permissions(&tmp_path, perms)?; fs::set_permissions(&tmp_path, perms)?;
#[cfg(unix)] #[cfg(unix)]