diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-07-31 21:26:06 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-07-31 21:51:53 +0100 |
| commit | a91361fac8a4ed4f0512c21ea36f12f79e279c6d (patch) | |
| tree | e1e0eb9df768d1a52cdf00b2705cb492af9c6955 | |
| parent | 9f60e2f37747690576c083639ddfacfadee140a7 (diff) | |
| download | mullvadvpn-a91361fac8a4ed4f0512c21ea36f12f79e279c6d.tar.xz mullvadvpn-a91361fac8a4ed4f0512c21ea36f12f79e279c6d.zip | |
Improve Linux DNS static-file management resiliency
| -rw-r--r-- | talpid-core/src/dns/linux/static_resolv_conf.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/talpid-core/src/dns/linux/static_resolv_conf.rs b/talpid-core/src/dns/linux/static_resolv_conf.rs index 73c9aa4221..b783c439de 100644 --- a/talpid-core/src/dns/linux/static_resolv_conf.rs +++ b/talpid-core/src/dns/linux/static_resolv_conf.rs @@ -11,6 +11,7 @@ use std::{ use talpid_types::ErrorExt; const RESOLV_CONF_BACKUP_PATH: &str = "/etc/resolv.conf.mullvadbackup"; +const RESOLV_CONF_DIR: &str = "/etc/"; pub type Result<T> = std::result::Result<T, Error>; @@ -114,7 +115,7 @@ impl DnsWatcher { let mut watcher = notify::raw_watcher(event_tx).map_err(Error::WatchResolvConf)?; watcher - .watch(RESOLV_CONF_PATH, RecursiveMode::NonRecursive) + .watch(&RESOLV_CONF_DIR, RecursiveMode::NonRecursive) .map_err(Error::WatchResolvConf)?; thread::spawn(move || Self::event_loop(event_rx, &state)); @@ -123,16 +124,22 @@ impl DnsWatcher { } fn event_loop(events: mpsc::Receiver<notify::RawEvent>, state: &Arc<Mutex<Option<State>>>) { - for _ in events { - let mut locked_state = state.lock(); - - if let Err(error) = Self::update(locked_state.as_mut()) { - log::error!( - "{}", - error.display_chain_with_msg( - "Failed to update DNS state after DNS settings changed" - ) - ); + for event in events { + if event + .path + .as_ref() + .map(|p| p.as_path() == &RESOLV_CONF_PATH.as_ref()) + .unwrap_or(false) + { + let mut locked_state = state.lock(); + if let Err(error) = Self::update(locked_state.as_mut()) { + log::error!( + "{}", + error.display_chain_with_msg( + "Failed to update DNS state after DNS settings changed" + ) + ); + } } } } |
