Skip to content

Commit

Permalink
Merge pull request #413 from Luap99/dead-code
Browse files Browse the repository at this point in the history
server: remove unused kill switch
  • Loading branch information
openshift-merge-bot[bot] authored Nov 30, 2023
2 parents 434de98 + 1525a69 commit 045f64e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
9 changes: 1 addition & 8 deletions src/dns/coredns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::env;
use std::fs::File;
use std::io::Read;
use std::net::{IpAddr, SocketAddr};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use tokio::net::UdpSocket;

// Containers can be recreated with different ips quickly so
Expand All @@ -33,7 +33,6 @@ pub struct CoreDns {
address: IpAddr, // server address
port: u32, // server port
backend: Arc<DNSBackend>, // server's data store
kill_switch: Arc<Mutex<bool>>, // global kill_switch
filter_search_domain: String, // filter_search_domain
rx: async_broadcast::Receiver<bool>, // kill switch receiver
resolv_conf: resolv_conf::Config, // host's parsed /etc/resolv.conf
Expand All @@ -50,7 +49,6 @@ impl CoreDns {
forward_addr: IpAddr,
forward_port: u16,
backend: Arc<DNSBackend>,
kill_switch: Arc<Mutex<bool>>,
filter_search_domain: String,
rx: async_broadcast::Receiver<bool>,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -92,7 +90,6 @@ impl CoreDns {
address,
port,
backend,
kill_switch,
filter_search_domain,
rx,
resolv_conf,
Expand Down Expand Up @@ -173,10 +170,6 @@ impl CoreDns {
self.backend.name_mappings
);
trace!("server backend.ip_mappings: {:?}", self.backend.ip_mappings);
trace!(
"server backend kill switch: {:?}",
self.kill_switch.lock().is_ok()
);


// if record type is PTR try resolving early and return if record found
Expand Down
17 changes: 1 addition & 16 deletions src/server/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use signal_hook::iterator::Signals;
use std::fs;
use std::net::IpAddr;
use std::net::Ipv4Addr;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::thread;

use async_broadcast::broadcast;
Expand Down Expand Up @@ -75,12 +75,6 @@ fn core_serve_loop(
Ok((backend, listen_ip_v4, listen_ip_v6)) => {
let mut thread_handles = vec![];

// we need mutex so we so threads can still modify lock
// clippy is only doing linting and asking us to use atomic bool
// so manually allow this
#[allow(clippy::mutex_atomic)]
let kill_switch = Arc::new(Mutex::new(false));

// kill server if listen_ip's are empty
if listen_ip_v4.is_empty() && listen_ip_v6.is_empty() {
//no configuration found kill the server
Expand Down Expand Up @@ -113,14 +107,12 @@ fn core_serve_loop(
let network_name_clone = network_name.clone();
let filter_search_domain_clone = filter_search_domain.to_owned();
let backend_arc_clone = shareable_arc.clone();
let kill_switch_arc_clone = Arc::clone(&kill_switch);
let receiver = rx.clone();
let handle = thread::spawn(move || {
if let Err(_e) = start_dns_server(
&network_name_clone,
IpAddr::V4(ip),
backend_arc_clone,
kill_switch_arc_clone,
port,
filter_search_domain_clone.to_string(),
receiver,
Expand All @@ -144,14 +136,12 @@ fn core_serve_loop(
let network_name_clone = network_name.clone();
let filter_search_domain_clone = filter_search_domain.to_owned();
let backend_arc_clone = shareable_arc.clone();
let kill_switch_arc_clone = Arc::clone(&kill_switch);
let receiver = rx.clone();
let handle = thread::spawn(move || {
if let Err(_e) = start_dns_server(
&network_name_clone,
IpAddr::V6(ip),
backend_arc_clone,
kill_switch_arc_clone,
port,
filter_search_domain_clone.to_string(),
receiver,
Expand All @@ -177,9 +167,6 @@ fn core_serve_loop(

if handle_signal.join().is_ok() {
send_broadcast(&tx);
if let Ok(mut switch) = kill_switch.lock() {
*switch = true;
};
}

for handle in thread_handles {
Expand All @@ -206,7 +193,6 @@ async fn start_dns_server(
name: &str,
addr: IpAddr,
backend_arc: DNSBackendWithArc,
kill_switch: Arc<Mutex<bool>>,
port: u32,
filter_search_domain: String,
rx: async_broadcast::Receiver<bool>,
Expand All @@ -219,7 +205,6 @@ async fn start_dns_server(
forward,
53_u16,
backend_arc.backend,
kill_switch,
filter_search_domain,
rx,
)
Expand Down

0 comments on commit 045f64e

Please sign in to comment.