Skip to content

Commit

Permalink
Merge pull request #182 from 56quarters/default-resolv
Browse files Browse the repository at this point in the history
Use constant for default resolv.conf path in binaries
  • Loading branch information
56quarters authored Aug 18, 2024
2 parents 3cf2192 + 1dd6552 commit 17d66e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
9 changes: 3 additions & 6 deletions mtop/src/bin/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tracing::{Instrument, Level};

const DEFAULT_RECORD_TYPE: RecordType = RecordType::A;
const DEFAULT_RECORD_CLASS: RecordClass = RecordClass::INET;
const DEFAULT_RESOLV_CONF: &str = "/etc/resolv.conf";
const MIN_PING_INTERVAL_SECS: f64 = 0.1;

/// dns: Make DNS queries or read/write binary format DNS messages
Expand Down Expand Up @@ -58,7 +59,7 @@ struct PingCommand {

/// Path to resolv.conf file for loading DNS configuration information. If this file
/// can't be loaded, default values for DNS configuration are used instead.
#[arg(long, default_value = default_resolv_conf().into_os_string(), value_hint = ValueHint::FilePath)]
#[arg(long, default_value = DEFAULT_RESOLV_CONF, value_hint = ValueHint::FilePath)]
resolv_conf: PathBuf,

/// Nameserver to use for DNS queries, overriding whatever nameserver is configured in
Expand Down Expand Up @@ -97,7 +98,7 @@ fn parse_interval(s: &str) -> Result<f64, String> {
struct QueryCommand {
/// Path to resolv.conf file for loading DNS configuration information. If this file
/// can't be loaded, default values for DNS configuration are used instead.
#[arg(long, default_value = default_resolv_conf().into_os_string(), value_hint = ValueHint::FilePath)]
#[arg(long, default_value = DEFAULT_RESOLV_CONF, value_hint = ValueHint::FilePath)]
resolv_conf: PathBuf,

/// Nameserver to use for DNS queries, overriding whatever nameserver is configured in
Expand Down Expand Up @@ -129,10 +130,6 @@ struct QueryCommand {
name: Name,
}

fn default_resolv_conf() -> PathBuf {
PathBuf::from("/etc/resolv.conf")
}

/// Read a binary format DNS message from standard input and display it as dig-like text output.
#[derive(Debug, Args)]
struct ReadCommand {}
Expand Down
6 changes: 1 addition & 5 deletions mtop/src/bin/mc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct McConfig {

/// Path to resolv.conf file for loading DNS configuration information. If this file
/// can't be loaded, default values for DNS configuration are used instead.
#[arg(long, env = "MC_RESOLV_CONF", default_value = default_resolv_conf().into_os_string(), value_hint = ValueHint::FilePath)]
#[arg(long, env = "MC_RESOLV_CONF", default_value = "/etc/resolv.conf", value_hint = ValueHint::FilePath)]
resolv_conf: PathBuf,

/// Memcached host to connect to in the form 'hostname:port'.
Expand Down Expand Up @@ -77,10 +77,6 @@ struct McConfig {
mode: Action,
}

fn default_resolv_conf() -> PathBuf {
PathBuf::from("/etc/resolv.conf")
}

fn parse_server_name(s: &str) -> Result<ServerName<'static>, InvalidDnsNameError> {
ServerName::try_from(s).map(|n| n.to_owned())
}
Expand Down
6 changes: 1 addition & 5 deletions mtop/src/bin/mtop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct MtopConfig {

/// Path to resolv.conf file for loading DNS configuration information. If this file
/// can't be loaded, default values for DNS configuration are used instead.
#[arg(long, env = "MTOP_RESOLV_CONF", default_value = default_resolv_conf().into_os_string(), value_hint = ValueHint::FilePath)]
#[arg(long, env = "MTOP_RESOLV_CONF", default_value = "/etc/resolv.conf", value_hint = ValueHint::FilePath)]
resolv_conf: PathBuf,

/// Timeout for connecting to Memcached and fetching statistics, in seconds.
Expand Down Expand Up @@ -84,10 +84,6 @@ struct MtopConfig {
hosts: Vec<String>,
}

fn default_resolv_conf() -> PathBuf {
PathBuf::from("/etc/resolv.conf")
}

fn parse_server_name(s: &str) -> Result<ServerName<'static>, InvalidDnsNameError> {
ServerName::try_from(s).map(|n| n.to_owned())
}
Expand Down

0 comments on commit 17d66e8

Please sign in to comment.