]> git.proxmox.com Git - pve-common.git/commitdiff
read_etc_network_interfaces: less strict parsing
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 25 Jun 2015 09:54:24 +0000 (11:54 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 26 Jun 2015 05:06:57 +0000 (07:06 +0200)
*) Don't require indented lines, instead know when to end a
   section.
*) Don't require empty lines between sections.
*) Fixed non-/greedy regex issue

And turned (.*)\s* into just (.*) as .* eats the whitespace
too.

src/PVE/INotify.pm

index fbedc506918a4ab7f528951426a62cce5aaec800..b39748c56310d1cbabf877ef4e697eb3e8828de2 100644 (file)
@@ -766,30 +766,39 @@ sub read_etc_network_interfaces {
 
     my $gateway = 0;
 
 
     my $gateway = 0;
 
-    while (defined ($line = <$fh>)) {
+    SECTION: while (defined ($line = <$fh>)) {
        chomp ($line);
        chomp ($line);
-       next if $line =~ m/^#/;
+       next if $line =~ m/^\s*#/;
  
  
-       if ($line =~ m/^auto\s+(.*)$/) {
+       if ($line =~ m/^\s*auto\s+(.*)$/) {
            my @aa = split (/\s+/, $1);
 
            foreach my $a (@aa) {
                $ifaces->{$a}->{autostart} = 1;
            }
 
            my @aa = split (/\s+/, $1);
 
            foreach my $a (@aa) {
                $ifaces->{$a}->{autostart} = 1;
            }
 
-       } elsif ($line =~ m/^iface\s+(\S+)\s+inet\s+(\S+)\s*$/) {
+       } elsif ($line =~ m/^\s*iface\s+(\S+)\s+inet\s+(\S+)\s*$/) {
            my $i = $1;
            $ifaces->{$i}->{method} = $2;
            $ifaces->{$i}->{priority} = $priority++;
 
            my $d = $ifaces->{$i};
            while (defined ($line = <$fh>)) {
            my $i = $1;
            $ifaces->{$i}->{method} = $2;
            $ifaces->{$i}->{priority} = $priority++;
 
            my $d = $ifaces->{$i};
            while (defined ($line = <$fh>)) {
-               if ($line =~ m/^\s*#(.*)\s*$/) {
+               chomp $line;
+               if ($line =~ m/^\s*#(.*?)\s*$/) {
                    # NOTE: we use 'comments' instead of 'comment' to 
                    # avoid automatic utf8 conversion
                    $d->{comments} = '' if !$d->{comments};
                    $d->{comments} .= "$1\n";
                    # NOTE: we use 'comments' instead of 'comment' to 
                    # avoid automatic utf8 conversion
                    $d->{comments} = '' if !$d->{comments};
                    $d->{comments} .= "$1\n";
-               } elsif ($line =~ m/^\s+((\S+)\s+(.+))$/) {
+               } elsif ($line =~ m/^\s*(?:iface\s
+                                          |mapping\s
+                                          |auto\s
+                                          |allow-
+                                          |source\s
+                                          |source-directory\s
+                                        )/x) {
+                   last;
+               } elsif ($line =~ m/^\s*((\S+)\s+(.+))$/) {
                    my $option = $1;
                    my ($id, $value) = ($2, $3);
                    if (($id eq 'address') || ($id eq 'netmask') || ($id eq 'broadcast')) {
                    my $option = $1;
                    my ($id, $value) = ($2, $3);
                    if (($id eq 'address') || ($id eq 'netmask') || ($id eq 'broadcast')) {
@@ -837,6 +846,8 @@ sub read_etc_network_interfaces {
                    last;
                }
            }
                    last;
                }
            }
+           last SECTION if !defined($line);
+           redo SECTION;
        }
     }
 
        }
     }