[pve-devel] [PATCH] pve-manager: use domain instead of search in /etc/resolv.conf

damien piquet piqudam at gmail.com
Fri Mar 8 16:49:25 CET 2013


This version uses the first entry of search if no domain is found.
When edited, it creates or replaces domain entry. It does not update
search entries at all.

I still have to change the field name in the interface and limit input
to only one domain, but I'll send another patch for this.

2013/3/8 Damien PIQUET <piqudam at gmail.com>:
>
> Signed-off-by: Damien PIQUET <piqudam at gmail.com>
> ---
>  data/PVE/INotify.pm |   20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/data/PVE/INotify.pm b/data/PVE/INotify.pm
> index 850668a..35c71b9 100644
> --- a/data/PVE/INotify.pm
> +++ b/data/PVE/INotify.pm
> @@ -532,13 +532,18 @@ sub read_etc_resolv_conf {
>      my ($filename, $fh) = @_;
>
>      my $res = {};
> +    my $search;
>
>      my $nscount = 0;
>      while (my $line = <$fh>) {
>         chomp $line;
> -       if ($line =~ m/^(search|domain)\s+(\S+)\s*/) {
> -           $res->{search} = $2;
> -       } elsif ($line =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*/) {
> +       if ($line =~ m/^search\s+(.+)/) {
> +           $search = $1;
> +       }
> +       elsif ($line =~ m/^domain\s+(.+)/) {
> +           $res->{search} = $1;
> +       }
> +       elsif ($line =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*/) {
>             $nscount++;
>             if ($nscount <= 3) {
>                 $res->{"dns$nscount"} = $1;
> @@ -546,6 +551,11 @@ sub read_etc_resolv_conf {
>         }
>      }
>
> +    if (!defined $res->{search} && $search) {
> +       $search =~ m/(\S+)/;
> +       $res->{search} = $1;
> +    }
> +
>      return $res;
>  }
>
> @@ -554,7 +564,7 @@ sub update_etc_resolv_conf {
>
>      my $data = "";
>
> -    $data = "search $resolv->{search}\n"
> +    $data = "domain $resolv->{search}\n"
>         if $resolv->{search};
>
>      my $written = {};
> @@ -567,7 +577,7 @@ sub update_etc_resolv_conf {
>      }
>
>      while (my $line = <$fh>) {
> -       next if $line =~ m/^(search|domain|nameserver)\s+/;
> +       next if $line =~ m/^(domain|nameserver)\s+/;
>         $data .= $line
>      }
>
> --
> 1.7.10.4
>



More information about the pve-devel mailing list