From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 6612B99E8B
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 21:00:08 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 315B019B2F
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 21:00:08 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 21:00:06 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 381EB439B7
 for <pve-devel@lists.proxmox.com>; Thu, 16 Nov 2023 21:00:06 +0100 (CET)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 16 Nov 2023 20:59:47 +0100
Message-Id: <20231116195947.1538515-1-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.39.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.089 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pve-devel] [PATCH installer] run env: do not store emtpy hostname
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 16 Nov 2023 20:00:08 -0000

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: bda1cdf699a3fcfc1cf3cfa446b1493689fc8eb8
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 Proxmox/Install/RunEnv.pm | 4 +++-
 Proxmox/Sys/Net.pm        | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

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;
-- 
2.39.2