From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 6BDF71FF135 for ; Sun, 22 Feb 2026 12:02:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3C7D61F83B; Sun, 22 Feb 2026 12:02:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mayr-stefan.de; s=manitu-webhosting; t=1771758129; bh=7MuX/uPBRIp978C869aL4naKQfF5X7OiFoZ2vmx+2Tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=5bvZIpOZM2CWyEuzllNS3hjUFXI7Fggocvg+OdM4K12+2XEGg5nrM9KCP3tG8n+H0 6P+iDpsLqC5n2cbB3Yf2MDKXIzKOrkFMUdNImmP12dr4xEaG9EjsUZsHrq2E3cfPnh ui/Pt3EfY0tmRqtpm2qfO+THq7GeaUQQ0aMKK/KjYXO6+a6mHXnpAumu1JgzjhTq7g 6PWc3lpzBXy37ABFtILUpD5bBZEjWTgB3EpXsR3AYADvWZow6p0wANrffXGTIfQ0ko Y7+RwM4oOU7ELI1eyUbhbJenQGygMPKfuy83PsKsE1w8+nVwrE9LIYFTZWP1F2bcD8 nSdsvur8ja6yw== From: Stefan Mayr To: pve-devel@lists.proxmox.com Subject: [PATCH common v3 1/2] Fix #7175: replace timezone handling with systemd timedatectl Date: Sun, 22 Feb 2026 12:02:04 +0100 Message-Id: <20260222110205.582-2-stefan@mayr-stefan.de> In-Reply-To: <20260220124809.076116bb@rosa.proxmox.com> References: <20260220124809.076116bb@rosa.proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.105 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_MISSING 0.1 Missing DMARC policy SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: VKYEXFZWYHC5WESQNNKISPHGATDJF2FK X-Message-ID-Hash: VKYEXFZWYHC5WESQNNKISPHGATDJF2FK X-MailFrom: stefan@mayr-stefan.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: s.ivanov@proxmox.com List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Usage of /etc/timezone is deprecated. The tzdata maintainers recommend switching to timedatectl. This adds timezone handling to the Systemd module and marks the functions in the INotify module as deprecated. Suggested-by: Fabian Grünbichler Suggested-by: Maximiliano Sandroval Tested-by: Stoiko Ivanov Reviewed-by: Stoiko Ivanov Signed-off-by: Stefan Mayr --- src/PVE/INotify.pm | 2 ++ src/PVE/Systemd.pm | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index 62b3ca8..fdec8f1 100644 --- a/src/PVE/INotify.pm +++ b/src/PVE/INotify.pm @@ -651,6 +651,7 @@ register_file( \&update_etc_resolv_conf, ); +# Deprecated: use PVE::Systemd::get_timezone() instead sub read_etc_timezone { my ($filename, $fd) = @_; @@ -661,6 +662,7 @@ sub read_etc_timezone { return $timezone; } +# Deprecated: use PVE::Systemd::set_timezone($timezone) instead sub write_etc_timezone { my ($filename, $fh, $timezone) = @_; diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm index 6ff0dc8..aabb774 100644 --- a/src/PVE/Systemd.pm +++ b/src/PVE/Systemd.pm @@ -10,7 +10,8 @@ use Net::DBus::Reactor; use POSIX qw(EINTR); use Socket qw(SOCK_DGRAM); -use PVE::Tools qw(file_set_contents file_get_contents trim); +use PVE::Exception qw(raise_param_exc); +use PVE::Tools qw(file_set_contents file_get_contents run_command trim); sub escape_unit { my ($val, $is_path) = @_; @@ -285,6 +286,38 @@ sub write_ini { file_set_contents($filename, $content); } +# Use systemds timedatectl for managing timezone settings +sub get_timezone { + my $timezone; + + PVE::Tools::run_command( + ['timedatectl', 'show', '--property=Timezone', '--value'], + outfunc => sub { $timezone //= shift }, + ); + + return $timezone; +} + +sub set_timezone { + my ($timezone) = @_; + + raise_param_exc({ 'timezone' => "No such timezone" }) + if (!grep { $_ eq $timezone } list_timezones()); + + PVE::Tools::run_command(['timedatectl', 'set-timezone', $timezone]); +} + +sub list_timezones { + my @timezones = (); + + PVE::Tools::run_command( + ['timedatectl', 'list-timezones'], + outfunc => sub { push(@timezones, shift); }, + ); + + return @timezones; +} + =head3 notify() This is a pure Perl reimplementation of systemd's C mechanism as defined in -- 2.34.1