From: Stoiko Ivanov Date: Thu, 16 Nov 2023 19:59:47 +0000 (+0100) Subject: run env: do not store emtpy hostname X-Git-Url: https://git.proxmox.com/?p=pve-installer.git;a=commitdiff_plain;h=a8054233054e370782bd78d6e15e024674b692f0 run env: do not store emtpy hostname without this patch the hostname ends up as the empty string in run-env-info.json, which results in a parse-error in the TUI code (an empty string is not None, but still too short as hostname) Minimally tested on a VM. Fixes: bda1cdf ("run env: retrieve and store hostname from DHCP lease if available") Signed-off-by: Stoiko Ivanov --- diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm index 5f68d82..2d91401 100644 --- a/Proxmox/Install/RunEnv.pm +++ b/Proxmox/Install/RunEnv.pm @@ -268,7 +268,9 @@ sub query_installation_environment : prototype() { }; # Cannot be put directly in the above hash as it might return undef .. - $output->{network}->{hostname} = Proxmox::Sys::Net::get_dhcp_hostname(); + if ( my $hostname = Proxmox::Sys::Net::get_dhcp_hostname()) { + $output->{network}->{hostname} = $hostname; + } # FIXME: move whatever makes sense over to Proxmox::Sys::Net:: and keep that as single source, # it can then use some different structure just fine (after adapting the GTK GUI to that) but diff --git a/Proxmox/Sys/Net.pm b/Proxmox/Sys/Net.pm index 35d2abd..7415bf9 100644 --- a/Proxmox/Sys/Net.pm +++ b/Proxmox/Sys/Net.pm @@ -211,7 +211,7 @@ sub get_dhcp_hostname : prototype() { } close($fh); - return $1 if defined($name) && $name =~ m/^([^\.]+)(?:\.(?:\S+))?$/; + return $name if defined($name) && $name =~ m/^([^\.]+)(?:\.(?:\S+))?$/; } 1;