public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common] fix #3153: INotify: adding interface comment to inet6 section when this is the only section
@ 2021-06-25 10:48 Lorenz Stechauner
  2021-06-25 11:18 ` Thomas Lamprecht
  0 siblings, 1 reply; 3+ messages in thread
From: Lorenz Stechauner @ 2021-06-25 10:48 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
---
 src/PVE/INotify.pm | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 562a243..ce1efd1 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1156,6 +1156,12 @@ sub __read_etc_network_interfaces {
 	$d->{method} = 'manual' if !$d->{method};
 	$d->{method6} = 'manual' if !$d->{method6};
 
+	if ($d->{comments6}) {
+	    $d->{comments} = '' if !defined($d->{comments});
+	    $d->{comments} .= $d->{comments6};
+	    $d->{comments6} = undef;
+	}
+
 	$d->{families} ||= ['inet'];
     }
 
@@ -1242,7 +1248,7 @@ sub __interface_to_string {
     my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
 		 comments => 1, autostart => 1, options => 1,
 		 address => 1, netmask => 1, gateway => 1, broadcast => 1,
-		 method6 => 1, families => 1, options6 => 1,
+		 method6 => 1, families => 1, options6 => 1, comments6 => 1,
 		 address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 };
 
     if (!$first_block) {
@@ -1733,6 +1739,12 @@ NETWORKDOC
 	    }
 	}
 
+	# if 'inet6' is the only family or is at least a family in use
+	if ($d->{families}[0] eq 'inet6') {
+	    $d->{comments6} = $d->{comments};
+	    $d->{comments} = undef;
+	}
+
 	my $i = 0; # some options should be printed only once
 	$raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
     }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH common] fix #3153: INotify: adding interface comment to inet6 section when this is the only section
  2021-06-25 10:48 [pve-devel] [PATCH common] fix #3153: INotify: adding interface comment to inet6 section when this is the only section Lorenz Stechauner
@ 2021-06-25 11:18 ` Thomas Lamprecht
  2021-06-25 11:45   ` Lorenz Stechauner
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Lamprecht @ 2021-06-25 11:18 UTC (permalink / raw)
  To: Proxmox VE development discussion, Lorenz Stechauner

On 25.06.21 12:48, Lorenz Stechauner wrote:
> Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
> ---
>  src/PVE/INotify.pm | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
> index 562a243..ce1efd1 100644
> --- a/src/PVE/INotify.pm
> +++ b/src/PVE/INotify.pm
> @@ -1156,6 +1156,12 @@ sub __read_etc_network_interfaces {
>  	$d->{method} = 'manual' if !$d->{method};
>  	$d->{method6} = 'manual' if !$d->{method6};
>  
> +	if ($d->{comments6}) {
> +	    $d->{comments} = '' if !defined($d->{comments});
> +	    $d->{comments} .= $d->{comments6};
> +	    $d->{comments6} = undef;

rather than setting it to `undef`, in which case the hash element still exists, use
`delete`, which also returns the value.


So this could be:

if (my $comments6 = delete $d->{comments6}) {
    $d->{comments} = ($d->{comments}) // '') . $comments6;
}

Shorter and also more correct/robust.

> +	}
> +
>  	$d->{families} ||= ['inet'];
>      }
>  
> @@ -1242,7 +1248,7 @@ sub __interface_to_string {
>      my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
>  		 comments => 1, autostart => 1, options => 1,
>  		 address => 1, netmask => 1, gateway => 1, broadcast => 1,
> -		 method6 => 1, families => 1, options6 => 1,
> +		 method6 => 1, families => 1, options6 => 1, comments6 => 1,
>  		 address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 };
>  
>      if (!$first_block) {
> @@ -1733,6 +1739,12 @@ NETWORKDOC
>  	    }
>  	}
>  
> +	# if 'inet6' is the only family or is at least a family in use
> +	if ($d->{families}[0] eq 'inet6') {

shouldn't that include a length check like `scalar($d->{families}->@*) == 0` to be more safe/robust,
as else inet6 could be just be first by chance (did not really checked the context though)

> +	    $d->{comments6} = $d->{comments};
> +	    $d->{comments} = undef;

see above regarding use of delete

> +	}
> +
>  	my $i = 0; # some options should be printed only once
>  	$raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
>      }
> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH common] fix #3153: INotify: adding interface comment to inet6 section when this is the only section
  2021-06-25 11:18 ` Thomas Lamprecht
@ 2021-06-25 11:45   ` Lorenz Stechauner
  0 siblings, 0 replies; 3+ messages in thread
From: Lorenz Stechauner @ 2021-06-25 11:45 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion


On 25.06.21 13:18, Thomas Lamprecht wrote:
> On 25.06.21 12:48, Lorenz Stechauner wrote:
>> Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
>> ---
>>   src/PVE/INotify.pm | 14 +++++++++++++-
>>   1 file changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
>> index 562a243..ce1efd1 100644
>> --- a/src/PVE/INotify.pm
>> +++ b/src/PVE/INotify.pm
>> @@ -1156,6 +1156,12 @@ sub __read_etc_network_interfaces {
>>   	$d->{method} = 'manual' if !$d->{method};
>>   	$d->{method6} = 'manual' if !$d->{method6};
>>   
>> +	if ($d->{comments6}) {
>> +	    $d->{comments} = '' if !defined($d->{comments});
>> +	    $d->{comments} .= $d->{comments6};
>> +	    $d->{comments6} = undef;
> rather than setting it to `undef`, in which case the hash element still exists, use
> `delete`, which also returns the value.
>
>
> So this could be:
>
> if (my $comments6 = delete $d->{comments6}) {
>      $d->{comments} = ($d->{comments}) // '') . $comments6;
> }
>
> Shorter and also more correct/robust.
>
>> +	}
>> +
>>   	$d->{families} ||= ['inet'];
>>       }
>>   
>> @@ -1242,7 +1248,7 @@ sub __interface_to_string {
>>       my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
>>   		 comments => 1, autostart => 1, options => 1,
>>   		 address => 1, netmask => 1, gateway => 1, broadcast => 1,
>> -		 method6 => 1, families => 1, options6 => 1,
>> +		 method6 => 1, families => 1, options6 => 1, comments6 => 1,
>>   		 address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 };
>>   
>>       if (!$first_block) {
>> @@ -1733,6 +1739,12 @@ NETWORKDOC
>>   	    }
>>   	}
>>   
>> +	# if 'inet6' is the only family or is at least a family in use
>> +	if ($d->{families}[0] eq 'inet6') {
> shouldn't that include a length check like `scalar($d->{families}->@*) == 0` to be more safe/robust,
> as else inet6 could be just be first by chance (did not really checked the context though)

the length check would not hurt - true. But it does not matter, in which 
section (inet/inet6) the comments gets put. The reader method unifies 
these comments anyway. So the comment *might* gets put in the inet6 
section, event if there is another inet section. Should not matter, 
should it?

Will add a "lenght" == 1 to the if.

>
>> +	    $d->{comments6} = $d->{comments};
>> +	    $d->{comments} = undef;
> see above regarding use of delete
>
>> +	}
>> +
>>   	my $i = 0; # some options should be printed only once
>>   	$raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
>>       }
>>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-25 11:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 10:48 [pve-devel] [PATCH common] fix #3153: INotify: adding interface comment to inet6 section when this is the only section Lorenz Stechauner
2021-06-25 11:18 ` Thomas Lamprecht
2021-06-25 11:45   ` Lorenz Stechauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal