]> git.proxmox.com Git - pve-installer.git/commitdiff
run env: do not store emtpy hostname
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 16 Nov 2023 19:59:47 +0000 (20:59 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 17 Nov 2023 05:25:43 +0000 (06:25 +0100)
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 <s.ivanov@proxmox.com>
Proxmox/Install/RunEnv.pm
Proxmox/Sys/Net.pm

index 5f68d82f9908af6982ab1c436d088bd78d62f3b6..2d91401dc472429d0ac1cee8a92f8de29b32cd7d 100644 (file)
@@ -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
index 35d2abde61631292b31ce0f182679745b1635b40..7415bf92f028f1688e9e2ef40d87f7ac6dda0553 100644 (file)
@@ -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;