Skip to content

Commit

Permalink
Fix update_dns_conf to avoid adding nameservers when the internal exi…
Browse files Browse the repository at this point in the history
…t nameserver is present
  • Loading branch information
thosmos committed Oct 6, 2023
1 parent ebe8c94 commit 8a5286f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rita_client/src/rita_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,22 @@ pub fn update_dns_conf() {
match File::open(resolv_path) {
Ok(file) => {
let reader = BufReader::new(file);
let mut found = false;
for line in reader.lines() {
let s = line.unwrap_or("".to_string());
if s.trim() == "nameserver 172.168.0.254" {
info!("Found nameserver 172.168.0.254, no update to resolv.conf");
found = true;
}
}
// if we get here we haven't found the nameserver and need to add it
match fs::write(resolv_path, updated_config) {
Ok(_) => info!("Updating resolv.conf"),
Err(e) => error!("Could not update resolv.conf with {:?}", e),
};

if !found {
// if we get here we haven't found the nameserver and need to add it
match fs::write(resolv_path, updated_config) {
Ok(_) => info!("Updating resolv.conf"),
Err(e) => error!("Could not update resolv.conf with {:?}", e),
};
}
}
Err(_e) => {
match fs::write(resolv_path, updated_config) {
Expand Down

0 comments on commit 8a5286f

Please sign in to comment.