[pve-devel] [PATCH common v3 2/2] Fix #1234: allows multiple search domains to be set

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Jun 9 13:22:19 CEST 2017


Isn't this #1270?

Also I think this should be patch 1 - as it looks like the tests from
patch 1 assume this patch to be applied?

On Thu, Apr 13, 2017 at 11:21:50AM +0200, Emmanuel Kasper wrote:
> Changes:
>  * multiple 'search' entries (up to 6) can be now read and added like the
>  libc resolver
>  * a 'search' entry list of more that 255 characters will be silently skipped,
>  like the libc resolver
> 
> When multiple 'domain' entries are defined, only the first one is matched, similar to
> previous behaviour and libc.
> ---
>  src/PVE/INotify.pm | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
> index 074f8b3..7cbfb64 100644
> --- a/src/PVE/INotify.pm
> +++ b/src/PVE/INotify.pm
> @@ -19,6 +19,7 @@ use Clone qw(clone);
>  use Linux::Inotify2;
>  use base 'Exporter';
>  use JSON; 
> +use English;

Please don't use this.

>  
>  our @EXPORT_OK = qw(read_file write_file register_file);
>  
> @@ -539,15 +540,29 @@ sub read_etc_resolv_conf {
>      my $nscount = 0;
>      while (my $line = <$fh>) {
>  	chomp $line;
> -	# resolv.conf should *either* have a search or domain, else behaviour is undefined
> -	# see res_init.c in libc, havesearch is set to 0 when a domain entry is found
> -	if ($line =~ m/^(search|domain)\s+(\S+)\s*/) {
> -	    $res->{search} = $2;
> -	} elsif ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) {
> +	# resolv.conf should *either* have a search or domain, else
> +	# last one found wins, see resolv.conf(5)
> +	if ($line =~ m/^domain\s+(?<local_domain>\S+)\s*/) {

Just use a regular match group rather than a named group, then you also
don't need to use %+, especially not %LAST_PAREN_MATCH. Just use $1.

Same for the matches below.

> +	    $res->{search} = $LAST_PAREN_MATCH{local_domain};
> +	    next;
> +	}
> +
> +	# up to 6 domains and 256 characters in the domain list, minus \0
> +	if ($line =~ /^search\s+(?<search_list>\S+(\s+\S+){0,5})\s*$/) {
> +	    if (length($LAST_PAREN_MATCH{search_list}) > 255)  {
> +		delete $res->{search}; #last one wins, even if empty
> +	    } else {
> +		$res->{search} = $LAST_PAREN_MATCH{search_list};
> +	    }
> +	    next;
> +	}
> +
> +	if ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) {
>  	    $nscount++;
>  	    if ($nscount <= 3) {
>  		$res->{"dns$nscount"} = $1;
>  	    }
> +	    next;
>  	}
>      }
>  
> -- 
> 2.1.4




More information about the pve-devel mailing list