From ddca45d3dc93847d619adc0788cd631e786c6a24 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 22 Dec 2009 14:10:29 -0800 Subject: Use perl to read resolv.conf Don't need to use grep to parse resolv.conf, perl is simpler and more powerful. --- scripts/vyatta-show-dhclient.pl | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/scripts/vyatta-show-dhclient.pl b/scripts/vyatta-show-dhclient.pl index 3ec4b8b..9a3ea74 100755 --- a/scripts/vyatta-show-dhclient.pl +++ b/scripts/vyatta-show-dhclient.pl @@ -71,6 +71,17 @@ sub dhclient_parse_vars { return %var_list; } +# Get current domain (if any) defined in resolv.conf +sub resolve_domain { + open (my $rc, '<', '/etc/resolv.conf') + or return; + + while (<$rc>) { + next unless m/^domain (\S+)/; + return $1; + } +} + sub dhclient_show_lease { my ($file) = @_; @@ -108,27 +119,14 @@ sub dhclient_show_lease { } } print "subnet mask: $new_subnet_mask\n" if defined $new_subnet_mask; - if (defined $new_domain_name) { - print "domain name: $new_domain_name"; - my $cli_domain_overrides = 0; - my $if_domain_exists = `grep domain /etc/resolv.conf 2> /dev/null | wc -l`; - if ($if_domain_exists > 0) { - my @domain = `grep domain /etc/resolv.conf`; - for my $each_domain_text_found (@domain) { - my @domain_text_split = split(/\t/, $each_domain_text_found, 2); - my $domain_at_start_of_line = $domain_text_split[0]; - chomp $domain_at_start_of_line; - if ($domain_at_start_of_line eq "domain") { - $cli_domain_overrides = 1; - } - } - } - if ($cli_domain_overrides == 1) { - print "\t[overridden by domain-name set using CLI]\n"; - } else { + if ($new_domain_name) { + print "domain name: $new_domain_name"; + my $cur_domain = resolve_doman(); + print "\t[overridden by domain-name set using CLI]" + if (defined $cur_domain && $cur_domain ne $new_domain_name); print "\n"; - } } + print "router : $new_routers\n" if defined $new_routers; print "name server: $new_domain_name_servers\n" if defined $new_domain_name_servers; -- cgit v1.2.3