From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 55DBC73605 for ; Thu, 7 Oct 2021 12:48:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4844D18854 for ; Thu, 7 Oct 2021 12:48:16 +0200 (CEST) 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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 76D881884A for ; Thu, 7 Oct 2021 12:48:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 504A044A62 for ; Thu, 7 Oct 2021 12:48:15 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Thu, 7 Oct 2021 12:48:03 +0200 Message-Id: <20211007104803.40204-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007104803.40204-1-f.ebner@proxmox.com> References: <20211007104803.40204-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.282 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [setup.pm, base.pm, proxmox.com] Subject: [pve-devel] [PATCH container 2/2] setup: also set contents of /etc/timezone X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 10:48:16 -0000 Some distributions like CentOS 8 and Gentoo don't have the file, so only update if it already existed. A slight change in behavior in set_timezone is that the warning will now trigger if /etc/localtime is a link to $tz_path, but $tz_path does not exist. Previously, it would return early if the link matched. Programs that rely on /etc/timezone within the container will now see the configured timezone too. While that is more correct, it's still a change that might be unexpected. Reported in the community forum: https://forum.proxmox.com/threads/pct-create-command-with-timezone-host-option-fails-to-create-a-container.97538/ Signed-off-by: Fabian Ebner --- Does this need to wait until PVE 8.0, because of potential breakage? src/PVE/LXC/Setup.pm | 1 + src/PVE/LXC/Setup/Base.pm | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm index 7c377ab..5cc56af 100644 --- a/src/PVE/LXC/Setup.pm +++ b/src/PVE/LXC/Setup.pm @@ -114,6 +114,7 @@ sub new { # Cache some host files we need access to: $plugin->{host_resolv_conf} = PVE::INotify::read_file('resolvconf'); + $plugin->{host_timezone} = PVE::INotify::read_file('timezone'); abs_path('/etc/localtime') =~ m|^(/.+)| or die "invalid /etc/localtime\n"; # untaint $plugin->{host_localtime} = $1; diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm index 04332ea..dafd69a 100644 --- a/src/PVE/LXC/Setup/Base.pm +++ b/src/PVE/LXC/Setup/Base.pm @@ -469,12 +469,18 @@ sub set_timezone { $tz_path = $self->{host_localtime}; } - return if abs_path('/etc/localtime') eq $tz_path; - if ($self->ct_file_exists($tz_path)) { - my $tmpfile = "localtime.$$.new.tmpfile"; - $self->ct_symlink($tz_path, $tmpfile); - $self->ct_rename($tmpfile, "/etc/localtime"); + if (abs_path('/etc/localtime') ne $tz_path) { + my $tmpfile = "localtime.$$.new.tmpfile"; + $self->ct_symlink($tz_path, $tmpfile); + $self->ct_rename($tmpfile, "/etc/localtime"); + } + + # not all distributions have /etc/timezone + if ($self->ct_file_exists('/etc/timezone')) { + my $contents = $zoneinfo eq 'host' ? $self->{host_timezone} : $zoneinfo; + $self->ct_file_set_contents('/etc/timezone', "$contents\n"); + } } else { warn "container does not have $tz_path, timezone can not be modified\n"; } -- 2.30.2